package com.open.capacity.workflow3.service.impl;

import com.open.capacity.form.service.FormDbTableService;
import com.open.capacity.model.system.SysUser;
import com.open.capacity.reimburse.util.uuid.UUIDUtils;
import com.open.capacity.salary.entity.GzTax;
import com.open.capacity.user.model.SysFile;
import com.open.capacity.user.model.SysUserRelation;
import com.open.capacity.user.service.SysFileService;
import com.open.capacity.user.service.SysPostService;
import com.open.capacity.user.service.SysUserRelationService;
import com.open.capacity.user.service.SysUserService;
import com.open.capacity.utils.DateUtil;
import com.open.capacity.utils.IdGenerator;
import com.open.capacity.utils.MapUtil;
import com.open.capacity.utils.PageUtil;
import com.open.capacity.workflow.dao.WFDynamicScriptDao;
import com.open.capacity.workflow.model.WFProcessinstance;
import com.open.capacity.workflow3.dao.*;
import com.open.capacity.workflow3.engine.*;
import com.open.capacity.workflow3.entity.*;
import com.open.capacity.workflow3.entity.NwfScheme;
import com.open.capacity.workflow3.service.NwfConfluenceService;
import com.open.capacity.workflow3.service.NwfSchemeService;
import com.open.capacity.workflow3.service.NwfTaskService;
import com.open.capacity.workflow3.util.ReflectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.open.capacity.commons.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.open.capacity.commons.CodeEnum;

import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.collections4.MapUtils;

import com.open.capacity.workflow3.service.NwfProcessService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

@Slf4j
@Service
public class NwfProcessServiceImpl implements NwfProcessService, GetConfluenceNumInterface {

    @Autowired
    private NwfProcessDao nwfProcessDao;

    @Autowired
    private NwfSchemeService schemeService;

    @Autowired
    private NwfTaskService taskService;

    @Autowired
    private NwfConfluenceService confluenceService;


    @Autowired
    private SysFileService fileService;

    @Autowired
    private SysUserService userService;

    @Autowired
    private SysPostService postService;

    @Autowired
    private SysUserRelationService userRelationService;

    @Autowired
    private NwfProcessDao processDao;

    @Autowired
    private NwfDelegateRuleDao delegateRuleDao;

    @Autowired
    private NwfConfluenceDao confluenceDao;
    @Autowired
    private NwfTaskDao taskDao;

    @Autowired
    private NwfTaskRelationDao taskRelationDao;

    @Autowired
    private NwfTaskMsgDao taskMsgDao;

    @Autowired
    private NwfTaskLogDao taskLogDao;

    @Autowired
    private WFDynamicScriptDao dynamicScriptDao;

    @Autowired
    private FormDbTableService formDbTableService;


    public NwfProcess findById(String id) {
        return processDao.findById(id);
    }

    public PageResult<NwfProcess> getPageList(Map<String, Object> params) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        if (MapUtils.getInteger(params, "page") != null && MapUtils.getInteger(params, "limit") != null)
            PageHelper.startPage(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"), true);

        String categoryId = params.containsKey("categoryId") ? params.get("categoryId").toString() : "";
        if (StringUtils.isNotEmpty(categoryId)) {
            params.put("isFinished", categoryId.equals("1") ? 0 : 1);
        }
        List<NwfProcess> list = processDao.findAll(params);
        PageInfo<NwfProcess> pageInfo = new PageInfo(list);
        for (NwfProcess item : list) {
            Map<String, Object> p1 = new HashMap<>();
            p1.put("processId", item.getId());
            p1.put("isFinished", 0);
            List<NwfTask> taskList = taskDao.findAll(p1);
            if (item.getIsFinished() != 1 && CollectionUtils.isEmpty(taskList)) {
                item.setEnabledMark(500);
            }
        }
        return PageResult.<NwfProcess>builder().data(pageInfo.getList()).resp_code(CodeEnum.SUCCESS.getCode()).count(pageInfo.getTotal()).build();
    }

    @Override
    public PageResult<NwfProcess> getMyPageList(String userId, Map<String, Object> params, String schemeCode) {
        Date startTime = params.containsKey("startTime") ? DateUtil.parse(params.get("startTime").toString()) : new Date();
        Date endTime = params.containsKey("endTime") ? DateUtil.parse(params.get("endTime").toString()) : new Date();
        String keyword = params.containsKey("keyword") ? params.get("keyword").toString() : "";

        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        if (MapUtils.getInteger(params, "page") != null && MapUtils.getInteger(params, "limit") != null) PageHelper.startPage(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"), true);

        params.put("createUserid", userId);
        params.put("isChild", 0);
        List<NwfProcess> list = processDao.findAll(params);
        PageInfo<NwfProcess> pageInfo = new PageInfo(list);

        return PageResult.<NwfProcess>builder().data(pageInfo.getList()).resp_code(CodeEnum.SUCCESS.getCode()).count(pageInfo.getTotal()).build();

    }

    public PageResult<NwfProcess> getMyTaskPageList(SysUser userInfo, Map<String, Object> params, String schemeCode, Boolean isBatchAudit) {
        Date startTime = params.containsKey("startTime") ? DateUtil.parse(params.get("startTime").toString()) : new Date();
        Date endTime = params.containsKey("endTime") ? DateUtil.parse(params.get("endTime").toString()) : new Date();
        String keyword = params.containsKey("keyword") ? params.get("keyword").toString() : "";

        String userId = userInfo.getId();
        StringBuilder strSql = new StringBuilder();
        strSql.append("SELECT t.id AS taskId, t.task_type as taskType,t.node_name AS taskName,t.is_urge as isUrge,t.update_time as updateTime,p.id,p.scheme_id as schemeId,p.scheme_code as schemeCode,p.scheme_name schemeName,p.code,p.process_title as processTitle,p.process_level as processLevel,p.enabled_mark as enabledMark,p.is_again as isAgain,p.is_finished as isFinished,p.is_child as isChild,p.parent_task_id as parentTaskId,p.parent_process_id as parentProcessId,p.create_userid as createUserid,p.create_username as createUsername,p.is_start as isStart " + " FROM(SELECT task_id FROM nwf_task_relation r1 " + " LEFT JOIN nwf_task t1 ON r1.task_id = t1.id " + " WHERE r1.mark = 0 AND r1.result = 0 AND (r1.userid  = #{userId}  ");
        for (SysUser item : getDelegateProcess(userId)) {
            String processId = "'" + item.getWfProcessId().replaceAll(",", "','") + "'";
            String userI2 = "'" + item.getId() + "'";
            strSql.append("  OR (r1.userid =" + userI2 + " AND t1.process_id in (" + processId + ") AND t1.task_type != 2 )");
        }
        strSql.append(") GROUP BY task_id) r" + " LEFT JOIN nwf_task t ON t.id = r.task_id" + " LEFT JOIN nwf_process p ON p.id = t.process_id" + " WHERE t.is_finished = 0  AND (p.is_finished = 0 OR t.task_type = 2 OR t.task_type = 4 OR t.task_type = 6)");

        if (params.containsKey("startTime") && params.containsKey("endTime")) {
            strSql.append(" AND ( t.update_time >= #{startTime} AND  t.update_time <= #{endTime} ) ");
        }

        if (StringUtils.isNotEmpty(keyword)) {
            strSql.append(" AND ( p.process_title like #{keyword} OR  p.scheme_name like #{keyword} ) ");
        }
        if (StringUtils.isNotEmpty(schemeCode)) {
            strSql.append(" AND p.scheme_code = #{schemeCode} ");
        }
        if (isBatchAudit != null && isBatchAudit) {
            strSql.append(" AND t.is_batch_audit = 1 ");
        }

        params.put("userId", userId);
        params.put("schemeCode", schemeCode);
        params.put("keyword", "%" + keyword + "%");
//        params.put("companyId", companyId);
//        params.put("departmentId", departmentId);
        params.put("sql", strSql.toString());

        int total = dynamicScriptDao.count(params);
        List<CaseInsensitiveMap<String, Object>> list;
        List<NwfProcess> modelList = new ArrayList<>();
        if (total > 0) {
            PageUtil.pageParamConver(params, true);
            list = dynamicScriptDao.pageList(params);
            try {
                for (Map<String, Object> map : list) {
                    NwfProcess item = MapUtil.mapToObject(map, NwfProcess.class);
                    modelList.add(item);
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error(e.getMessage());
            }
        }
        return PageResult.<NwfProcess>builder().data(modelList).resp_code(CodeEnum.SUCCESS.getCode()).count((long) total).build();
    }

    public PageResult<NwfProcess> getMyFinishTaskPageList(SysUser userInfo, Map<String, Object> params, String schemeCode) {
        Date startTime = params.containsKey("startTime") ? DateUtil.parse(params.get("startTime").toString()) : new Date();
        Date endTime = params.containsKey("endTime") ? DateUtil.parse(params.get("endTime").toString()) : new Date();
        String keyword = params.containsKey("keyword") ? params.get("keyword").toString() : "";

        String userId = userInfo.getId();
        StringBuilder strSql = new StringBuilder();
        strSql.append("SELECT t.task_id as taskId,t.task_type as taskType,t.task_name as taskName,t.create_time as createTime,p.id,p.scheme_id as schemeId,p.scheme_code as schemeCode,p.scheme_name as schemeName,p.code,p.process_title as processTitle,p.process_level as processLevel,p.enabled_mark as enabledMark,p.is_again as isAgain,p.is_finished as isFinished,p.is_child as isChild,p.parent_task_id as parentTaskId,p.parent_process_id as parentProcessId,p.create_userid as createUserid,p.create_username as createUsername,p.is_start as isStart " + " FROM (SELECT MAX(t.id) AS task_id,MAX(t.task_type) AS task_type,MAX(t.node_name) AS task_name,MAX(r.create_time) AS create_time,t.process_id " + " FROM nwf_task t LEFT JOIN nwf_task_relation r ON r.task_id = t.id " + " WHERE(r.result = 1 OR r.result = 2 OR r.result = 4) AND r.userid = #{userId} " + " GROUP BY t.node_id,process_id) t " + " LEFT JOIN nwf_process p ON t.process_id = p.id where 1=1 ");
        if (params.containsKey("startTime") && params.containsKey("endTime")) {
            strSql.append(" AND ( t.update_time >= #{startTime} AND  t.update_time <= #{endTime} ) ");
        }
        if (StringUtils.isNotEmpty(keyword)) {
            keyword = "%" + keyword + "%";
            strSql.append(" AND ( p.process_title like #{keyword} OR  p.scheme_name like #{keyword} ) ");
        }
        if (StringUtils.isNotEmpty(schemeCode)) {
            strSql.append(" AND p.scheme_code = #{schemeCode} ");
        }

        params.put("userId", userId);
        params.put("schemeCode", schemeCode);
        params.put("keyword", "%" + keyword + "%");
//        params.put("companyId", companyId);
//        params.put("departmentId", departmentId);
        params.put("sql", strSql.toString());

        int total = dynamicScriptDao.count(params);
        List<CaseInsensitiveMap<String, Object>> list;
        List<NwfProcess> modelList = new ArrayList<>();
        if (total > 0) {
            PageUtil.pageParamConver(params, true);
            list = dynamicScriptDao.pageList(params);
            try {
                for (Map<String, Object> map : list) {
                    NwfProcess item = MapUtil.mapToObject(map, NwfProcess.class);
                    modelList.add(item);
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error(e.getMessage());
            }
        }
        return PageResult.<NwfProcess>builder().data(modelList).resp_code(CodeEnum.SUCCESS.getCode()).count((long) total).build();
    }


    public void delete(String processId) {
        processDao.delete(processId);
    }

    public long getAgreeNum(String processId, String nodeId) {
        List<NwfConfluence> list = confluenceService.getList(processId, nodeId);
        return list.stream().filter(t -> t.getState() == 1).count();
    }

    public long getDisAgreeNum(String processId, String nodeId) {
        List<NwfConfluence> list = confluenceService.getList(processId, nodeId);
        return list.stream().filter(t -> t.getState() == 0).count();
    }

    private NwfIEngine _bootstraper(String code, String processId, String taskId, SysUser userInfo) {
        NwfEngineConfig nWFEngineConfig = new NwfEngineConfig();
        NwfEngineParamConfig nWFEngineParamConfig = (nWFEngineConfig.paramConfig = new NwfEngineParamConfig());
        if (userInfo != null) {
            nWFEngineParamConfig.currentUser = new NwfUserInfo();
            nWFEngineParamConfig.currentUser.id = userInfo.getId();
            nWFEngineParamConfig.currentUser.account = userInfo.getUserName();
            nWFEngineParamConfig.currentUser.name = userInfo.getRealName();
            nWFEngineParamConfig.currentUser.companyId = userInfo.getCompanyId();
            nWFEngineParamConfig.currentUser.departmentId = userInfo.getDepartmentId();
        }
        if (StringUtils.isNotEmpty(code)) {
            NwfSchemeinfo schemeInfo2 = schemeService.getInfoEntityByCode(code);
            if (schemeInfo2 != null) {
                NwfScheme data4 = schemeService.getSchemeEntity(schemeInfo2.getSchemeId());
                if (data4 != null) {
                    nWFEngineParamConfig.scheme = data4.getContent();
                    nWFEngineParamConfig.schemeCode = code;
                    nWFEngineParamConfig.schemeId = schemeInfo2.getSchemeId();
                    nWFEngineParamConfig.schemeName = schemeInfo2.getName();
                    nWFEngineParamConfig.processId = processId;
                    nWFEngineParamConfig.hasInstance = false;
                    nWFEngineParamConfig.createUser = nWFEngineParamConfig.currentUser;
                }
            }
        } else if (StringUtils.isNotEmpty(processId)) {
            NwfProcess processEntity2 = findById(processId);
            if (processEntity2 != null) {
                if (StringUtils.isEmpty(processEntity2.getSchemeId())) {
                    NwfSchemeinfo schemeInfo = schemeService.getInfoEntityByCode(processEntity2.getSchemeCode());
                    if (schemeInfo != null) {
                        NwfScheme data3 = schemeService.getSchemeEntity(schemeInfo.getSchemeId());
                        if (data3 != null) {
                            nWFEngineParamConfig.scheme = data3.getContent();
                            nWFEngineParamConfig.schemeCode = processEntity2.getSchemeCode();
                            nWFEngineParamConfig.schemeId = schemeInfo.getSchemeId();
                            nWFEngineParamConfig.schemeName = schemeInfo.getName();
                            nWFEngineParamConfig.processId = processId;
                            nWFEngineParamConfig.hasInstance = true;
                            nWFEngineParamConfig.createUser = nWFEngineParamConfig.currentUser;
                        }
                    }
                } else {
                    NwfScheme data2 = schemeService.getSchemeEntity(processEntity2.getSchemeId());
                    if (data2 != null) {
                        nWFEngineParamConfig.scheme = data2.getContent();
                        nWFEngineParamConfig.schemeCode = processEntity2.getSchemeCode();
                        nWFEngineParamConfig.schemeId = processEntity2.getSchemeId();
                        nWFEngineParamConfig.schemeName = processEntity2.getSchemeName();
                        nWFEngineParamConfig.isChild = processEntity2.getIsChild();
                        nWFEngineParamConfig.parentProcessId = processEntity2.getParentProcessId();
                        nWFEngineParamConfig.parentTaskId = processEntity2.getParentTaskId();
                        nWFEngineParamConfig.processId = processId;
                        nWFEngineParamConfig.hasInstance = true;
                        SysUser userEntity2 = userService.findById(processEntity2.getCreateUserid());
                        nWFEngineParamConfig.createUser = new NwfUserInfo();
                        nWFEngineParamConfig.createUser.id = processEntity2.getCreateUserid();
                        nWFEngineParamConfig.createUser.account = userEntity2.getUserName();
                        nWFEngineParamConfig.createUser.name = userEntity2.getRealName();
                        nWFEngineParamConfig.createUser.companyId = userEntity2.getCompanyId();
                        nWFEngineParamConfig.createUser.departmentId = userEntity2.getDepartmentId();

                    }
                }
            }
        } else if (StringUtils.isNotEmpty(taskId)) {
            NwfTask taskEntiy = taskService.getEntity(taskId);
            if (taskEntiy != null) {
                NwfProcess processEntity = findById(taskEntiy.getProcessId());
                if (processEntity != null) {
                    NwfScheme data = schemeService.getSchemeEntity(processEntity.getSchemeId());
                    if (data != null) {
                        nWFEngineParamConfig.scheme = data.getContent();
                        nWFEngineParamConfig.schemeCode = processEntity.getSchemeCode();
                        nWFEngineParamConfig.schemeId = processEntity.getSchemeId();
                        nWFEngineParamConfig.schemeName = processEntity.getSchemeName();
                        nWFEngineParamConfig.isChild = processEntity.getIsChild();
                        nWFEngineParamConfig.parentProcessId = processEntity.getParentProcessId();
                        nWFEngineParamConfig.parentTaskId = processEntity.getParentTaskId();
                        nWFEngineParamConfig.processId = processEntity.getId();
                        nWFEngineParamConfig.hasInstance = true;
                        SysUser userEntity = userService.findById(processEntity.getCreateUserid());

                        nWFEngineParamConfig.createUser = new NwfUserInfo();
                        nWFEngineParamConfig.createUser.id = processEntity.getCreateUserid();
                        nWFEngineParamConfig.createUser.account = userEntity.getUserName();
                        nWFEngineParamConfig.createUser.name = userEntity.getRealName();
                        nWFEngineParamConfig.createUser.companyId = userEntity.getCompanyId();
                        nWFEngineParamConfig.createUser.departmentId = userEntity.getDepartmentId();

                    }
                }
            }
        }

        nWFEngineConfig.dbTableService = formDbTableService;
        nWFEngineConfig.confluenceNumInterface = this;
        return new NwfEngine(nWFEngineConfig);
    }

    private List<NwfUserInfo> _getNodeAuditors(List<NwfAuditor> nodeAuditorList, NwfNodeInfo nodeInfo, NwfEngineParamConfig paramConfig) {
        List<NwfUserInfo> list = new ArrayList<>();
        List<NwfUserInfo> list2 = _getNodeAuditors2(nodeAuditorList, nodeInfo, paramConfig);
        NwfTask taskEntiy = null;
        if (StringUtils.isNotEmpty(paramConfig.processId)) {
            taskEntiy = taskService.getEntityByNodeId(nodeInfo.id, paramConfig.processId);
            if (taskEntiy != null) {
                if (taskEntiy.getIsFinished() == 0) {
                    return list;
                }
                List<NwfTaskRelation> taskUserList = taskService.getTaskUserList(taskEntiy.getId());
                if (nodeInfo.type.equals("stepnode") && nodeInfo.isAllAuditor.equals("2")) {
                    List<NwfTaskRelation> taskUserList2;
                    if (nodeInfo.auditorAgainType.equals("1")) {
                        taskUserList2 = taskUserList.stream().filter(t -> t.getResult() != 1).collect(Collectors.toList());
                        if (taskUserList2.size() == 0) {
                            taskUserList2 = taskUserList;
                        }
                    } else {
                        taskUserList2 = taskUserList;
                    }
                    if (taskUserList2.size() > 0) {
                        for (NwfTaskRelation item3 : taskUserList2) {
                            SysUser taskUserEntity2 = userService.findById(item3.getUserid());
                            if (taskUserEntity2 != null) {
                                NwfUserInfo user = new NwfUserInfo();
                                user.id = taskUserEntity2.getId();
                                user.account = taskUserEntity2.getUserName();
                                user.name = taskUserEntity2.getRealName();

                                list.add(user);
                            }
                        }
                        return list;
                    }
                } else {
                    NwfTaskRelation taskUser;
                    Optional<NwfTaskRelation> relationOptional = taskUserList.stream().filter(t -> t.getResult() != 0 && t.getResult() != 3).findFirst();
                    if (relationOptional.isPresent()) {
                        taskUser = relationOptional.get();
                        SysUser taskUserEntity = userService.findById(taskUser.getUserid());
                        if (taskUserEntity != null) {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = taskUserEntity.getId();
                            user.account = taskUserEntity.getUserName();
                            user.name = taskUserEntity.getRealName();
                            list.add(user);

                            String _userId = taskUserEntity.getId();

                            long count = list2.stream().filter(t -> t.getId().equals(_userId)).count();
                            if (count == 0) {
                                if (list2.size() == 0) {
//                                    if (nodeInfo.noPeopleGz == 3) {
//                                        throw new Exception("下一节点没有审核人,无法提交！");
//                                    }
                                    Assert.isTrue(nodeInfo.noPeopleGz != 3, "下一节点没有审核人,无法提交！");
                                    SysUser item2 = userService.findById("1");
                                    NwfUserInfo user2 = new NwfUserInfo();
                                    user2.id = item2.getId();
                                    user2.account = item2.getUserName();
                                    user2.name = item2.getRealName();
                                    user2.noPeople = true;
                                    list2.add(user2);

                                    return list2;
                                }
                                return list2;
                            }
                            return list;
                        }
                    }
                }
            }
        }
        list.addAll(list2);
        if (list.size() == 0) {
//            if (nodeInfo.noPeopleGz == 3) {
//                throw new Exception();
//            }
            Assert.isTrue(nodeInfo.noPeopleGz != 3, "下一节点没有审核人,无法提交！");
            SysUser item = userService.findById("1"); //系统管理员
            NwfUserInfo user = new NwfUserInfo();
            user.id = item.getId();
            user.account = item.getUserName();
            user.name = item.getRealName();
            user.noPeople = true;
            list.add(user);
            return list;
        }
        return list;
    }

    private List<NwfUserInfo> _getNodeAuditors2(List<NwfAuditor> nodeAuditorList, NwfNodeInfo nodeInfo, NwfEngineParamConfig paramConfig) {
        List<NwfUserInfo> list = new ArrayList<>();
        if (nodeAuditorList == null) {
            NwfUserInfo user = new NwfUserInfo();
            user.id = paramConfig.createUser.id;
            user.account = paramConfig.createUser.account;
            user.name = paramConfig.createUser.name;
            list.add(user);

            return list;
        }
        if (nodeAuditorList.size() == 0) {
            SysUser item2 = userService.findById("1"); //系统管理员
            NwfUserInfo user = new NwfUserInfo();
            user.id = item2.getId();
            user.account = item2.getUserName();
            user.name = item2.getRealName();
            list.add(user);
            return list;
        }
        for (NwfAuditor item : nodeAuditorList) {
            switch (item.type) {
                case 1:
                    for (SysUserRelation userRelation : userRelationService.findByObjectId(item.auditorId)) {
                        SysUser userEntity = userService.findById(userRelation.getUserId());
                        if (userEntity == null) {
                            continue;
                        }
                        if (item.condition == 1) {
                            if (userEntity.getDepartmentId().equals(paramConfig.createUser.getDepartmentId())) {
                                NwfUserInfo user = new NwfUserInfo();
                                user.id = userEntity.getId();
                                user.account = userEntity.getUserName();
                                user.name = userEntity.getRealName();
                                list.add(user);
                            }
                        } else if (item.condition == 2) {
                            if (userEntity.getCompanyId().equals(paramConfig.createUser.getCompanyId())) {
                                NwfUserInfo user = new NwfUserInfo();
                                user.id = userEntity.getId();
                                user.account = userEntity.getUserName();
                                user.name = userEntity.getRealName();
                                list.add(user);
                            }
                        } else {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = userEntity.getId();
                            user.account = userEntity.getUserName();
                            user.name = userEntity.getRealName();
                            list.add(user);
                        }
                    }
                    break;
                case 2:
                    for (SysUserRelation userRelation2 : userRelationService.findByObjectId(item.auditorId)) {
//                        new WfAuditor();
                        SysUser userEntity2 = userService.findById(userRelation2.getUserId());
                        if (userEntity2 == null) {
                            continue;
                        }
                        if (item.condition != null) {
                            if (item.condition == 1) {
                                if (userEntity2.getDepartmentId().equals(paramConfig.createUser.getDepartmentId())) {
                                    NwfUserInfo user = new NwfUserInfo();
                                    user.id = userEntity2.getId();
                                    user.account = userEntity2.getUserName();
                                    user.name = userEntity2.getRealName();
                                    list.add(user);
                                }
                            } else if (item.condition == 2) {
                                if (userEntity2.getCompanyId().equals(paramConfig.createUser.getCompanyId())) {
                                    NwfUserInfo user = new NwfUserInfo();
                                    user.id = userEntity2.getId();
                                    user.account = userEntity2.getUserName();
                                    user.name = userEntity2.getRealName();
                                    list.add(user);
                                }
                            } else if (item.condition == 3) {
                                List<String> postList3 = userRelationService.findByUserId(paramConfig.createUser.id).stream().filter(t -> t.getObjectType().equals("Post")).map(SysUserRelation::getObjectId).collect(Collectors.toList());
                                List<String> postList5 = userRelationService.findByUserId(userEntity2.getId()).stream().filter(t -> t.getObjectType().equals("Post")).map(SysUserRelation::getObjectId).collect(Collectors.toList());
                                if (postService.isUp(postList3, postList5)) {
                                    NwfUserInfo user = new NwfUserInfo();
                                    user.id = userEntity2.getId();
                                    user.account = userEntity2.getUserName();
                                    user.name = userEntity2.getRealName();
                                    list.add(user);
                                }
                            } else if (item.condition == 4) {
                                List<String> postList2 = userRelationService.findByUserId(paramConfig.createUser.id).stream().filter(t -> t.getObjectType().equals("Post")).map(SysUserRelation::getObjectId).collect(Collectors.toList());
                                List<String> postList4 = userRelationService.findByUserId(userEntity2.getId()).stream().filter(t -> t.getObjectType().equals("Post")).map(SysUserRelation::getObjectId).collect(Collectors.toList());
                                if (postService.isDown(postList2, postList4)) {
                                    NwfUserInfo user = new NwfUserInfo();
                                    user.id = userEntity2.getId();
                                    user.account = userEntity2.getUserName();
                                    user.name = userEntity2.getRealName();
                                    list.add(user);
                                }
                            }
                        } else {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = userEntity2.getId();
                            user.account = userEntity2.getUserName();
                            user.name = userEntity2.getRealName();
                            list.add(user);
                        }
                    }
                    break;
                case 3: {
                    if (StringUtils.isEmpty(item.auditorId)) {
                        break;
                    }
                    String[] array = item.auditorId.split(",");
                    for (String userItem : array) {
                        SysUser userEntity4 = userService.findById(userItem);
                        if (userEntity4 != null) {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = userEntity4.getId();
                            user.account = userEntity4.getUserName();
                            user.name = userEntity4.getRealName();
                            list.add(user);
                        }
                    }
                    break;
                }
                case 4: {
                    List<String> postId = userRelationService.findByUserId(paramConfig.createUser.id).stream().filter(t -> t.getObjectType().equals("Post")).map(SysUserRelation::getObjectId).collect(Collectors.toList());
                    int level = Integer.parseInt(item.auditorId);
                    List<String> postList;
                    if (level < 6) {
                        postList = postService.getUpIdList(postId, level);
                    } else {
                        level -= 5;
                        postList = postService.getDownIdList(postId, level);
                    }
                    for (SysUserRelation userRelationItem : userRelationService.findByObjectIds(postList)) {
//                        new WfAuditor();
                        SysUser userEntity3 = userService.findById(userRelationItem.getUserId());
                        if (userEntity3 != null) {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = userEntity3.getId();
                            user.account = userEntity3.getUserName();
                            user.name = userEntity3.getRealName();
                            list.add(user);
                        }
                    }
                    break;
                }
                case 5: {
                    if (StringUtils.isEmpty(item.auditorId)) {
                        break;
                    }
                    String[] idList = item.auditorId.split("|");
                    if (idList.length != 4) {
                        break;
                    }
                    String dbId = idList[0];
                    String table = idList[1];
                    String relationId = idList[2];
                    String id = idList[3];
                    String sql = "select " + id + " from " + table + " where " + relationId + " ='" + paramConfig.processId + "'";
                    for (Map<String, Object> row : formDbTableService.findData(dbId, sql, null)) {
                        SysUser userEntity5 = userService.findById(row.get(0).toString());
                        if (userEntity5 != null) {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = userEntity5.getId();
                            user.account = userEntity5.getUserName();
                            user.name = userEntity5.getRealName();
                            list.add(user);
                        }
                    }
                    break;
                }
                case 6: {
                    NwfTaskLog task = taskService.getLogEntityByNodeId(item.auditorId, paramConfig.processId);
                    if (task != null && StringUtils.isNotEmpty(task.getCreateUserid())) {
                        SysUser userEntity6 = userService.findById(task.getCreateUserid());
                        if (userEntity6 != null) {
                            NwfUserInfo user = new NwfUserInfo();
                            user.id = userEntity6.getId();
                            user.account = userEntity6.getUserName();
                            user.name = userEntity6.getRealName();
                            list.add(user);
                        }
                    }
                    break;
                }
            }
        }
        return list;
    }

    private List<NwfTask> _createTask(List<NwfNodeInfo> nodeList, NwfNodeInfo currentNodeInfo, NwfEngineParamConfig paramConfig) {
        List<NwfTask> list = new ArrayList<>();
        for (NwfNodeInfo node : nodeList) {
            NwfTask nWFTaskEntity = new NwfTask();
            nWFTaskEntity = nWFTaskEntity.create();
            nWFTaskEntity.setProcessId(paramConfig.processId);
            nWFTaskEntity.setNodeId(node.id);
            nWFTaskEntity.setNodeName(node.name);
            nWFTaskEntity.setPrevNodeId(currentNodeInfo.id);
            nWFTaskEntity.setPrevNodeName(currentNodeInfo.name);
            nWFTaskEntity.setCreateUserid(paramConfig.currentUser.id);
            nWFTaskEntity.setCreateUsername(paramConfig.currentUser.name);
            if (StringUtils.isNotEmpty(node.timeoutAction)) {
                nWFTaskEntity.setTimeoutAction(Integer.parseInt(node.timeoutAction));
            }
            if (StringUtils.isNotEmpty(node.timeoutInterval)) {
                nWFTaskEntity.setTimeoutInterval(Integer.parseInt(node.timeoutInterval));
            }
            if (StringUtils.isNotEmpty(node.timeoutNotice)) {
                nWFTaskEntity.setTimeoutNotice(Integer.parseInt(node.timeoutNotice));
            }
            if (StringUtils.isNotEmpty(node.timeoutStrategy)) {
                nWFTaskEntity.setTimeoutStrategy(node.timeoutStrategy);
            }
            nWFTaskEntity.userInfoList = _getNodeAuditors(node.auditors, node, paramConfig);
            switch (node.type) {
                case "stepnode":
                    nWFTaskEntity.setTaskType(1);
                    nWFTaskEntity.setIsBatchAudit(node.isBatchAudit);
                    if (!(node.isAllAuditor.equals("2")) || !(node.auditorType.equals("2"))) {
                        break;
                    }
                    for (NwfUserInfo nWFSysUser : nWFTaskEntity.userInfoList) {
                        nWFSysUser.setMark(1);
                    }
                    nWFTaskEntity.userInfoList.get(0).mark = 0;
                    break;
                case "auditornode":
                    nWFTaskEntity.setTaskType(2);
                    nWFTaskEntity.setIsBatchAudit(node.isBatchAudit);
                    break;
                case "childwfnode": {
                    NwfTask taskEntiy = taskService.getEntityByNodeId(node.id, paramConfig.processId);
                    if (taskEntiy == null) {
                        nWFTaskEntity.setChildProcessId(UUIDUtils.getOriginalUUIDWithoutBar());
                        nWFTaskEntity.setTaskType(4);
                        break;
                    }
                    NwfProcess cNwfProcess = findById(taskEntiy.getChildProcessId());
                    if (cNwfProcess.getIsFinished() == 1) {
                        nWFTaskEntity.setChildProcessId(taskEntiy.getChildProcessId());
                        nWFTaskEntity.setTaskType(6);
                        NwfIEngine nWFIEngine = _bootstraper("", taskEntiy.getChildProcessId(), "", null);
                        NwfTask nWFTaskEntity2 = new NwfTask();
                        nWFTaskEntity2 = nWFTaskEntity2.create();
                        nWFTaskEntity2.setProcessId(cNwfProcess.getId());
                        nWFTaskEntity2.setNodeId(nWFIEngine.getStartNode().id);
                        nWFTaskEntity2.setNodeName(nWFIEngine.getStartNode().name);
                        nWFTaskEntity2.setPrevNodeId(currentNodeInfo.id);
                        nWFTaskEntity2.setPrevNodeName(currentNodeInfo.name);
                        nWFTaskEntity2.setCreateUserid(paramConfig.currentUser.id);
                        nWFTaskEntity2.setCreateUsername(paramConfig.currentUser.name);
                        nWFTaskEntity2.setTaskType(5);
                        list.add(nWFTaskEntity2);
                    } else {
                        nWFTaskEntity.setTaskType(null);
                    }
                    break;
                }
                case "startround":
                    if (paramConfig.getIsChild() == 1) {
                        NwfTask pNwfTaskEntity = taskService.getEntity(paramConfig.parentTaskId);
                        nWFTaskEntity.setProcessId(paramConfig.parentProcessId);
                        nWFTaskEntity.setNodeId(pNwfTaskEntity.getNodeId());
                        nWFTaskEntity.setNodeName(pNwfTaskEntity.getNodeName());
                        nWFTaskEntity.setPrevNodeId(pNwfTaskEntity.getNodeId());
                        nWFTaskEntity.setPrevNodeName(pNwfTaskEntity.getNodeName());
                        nWFTaskEntity.setTaskType(6);
                        nWFTaskEntity.setChildProcessId(paramConfig.processId);

                        NwfTask nWFTaskEntity3 = new NwfTask();
                        nWFTaskEntity3 = nWFTaskEntity3.create();
                        nWFTaskEntity3.setProcessId(paramConfig.processId);
                        nWFTaskEntity3.setNodeId(node.id);
                        nWFTaskEntity3.setNodeName(node.name);
                        nWFTaskEntity3.setPrevNodeId(currentNodeInfo.id);
                        nWFTaskEntity3.setPrevNodeName(currentNodeInfo.name);
                        nWFTaskEntity3.setCreateUserid(paramConfig.currentUser.id);
                        nWFTaskEntity3.setCreateUsername(paramConfig.currentUser.name);
                        nWFTaskEntity3.setTaskType(5);
                        list.add(nWFTaskEntity3);
                    } else {
                        nWFTaskEntity.setTaskType(5);
                    }
                    break;
            }
            if (nWFTaskEntity.userInfoList != null && nWFTaskEntity.userInfoList.size() > 0 && nWFTaskEntity.getTaskType() != null) {
                list.add(nWFTaskEntity);
            }
        }
        return list;
    }

    private List<NwfTaskMsg> _createTaskMsg(List<NwfTask> taskList, NwfEngineParamConfig paramConfig) {
        List<NwfTaskMsg> list = new ArrayList<>();
        for (NwfTask task : taskList) {
            if (task.userInfoList == null) {
                continue;
            }
            for (NwfUserInfo item : task.userInfoList) {
                NwfTaskMsg nWFTaskMsgEntity = new NwfTaskMsg();
                nWFTaskMsgEntity = nWFTaskMsgEntity.create();
                nWFTaskMsgEntity.setProcessId(task.getProcessId());
                nWFTaskMsgEntity.setTaskId(task.getId());
                nWFTaskMsgEntity.setFromUserid(paramConfig.currentUser.id);
                nWFTaskMsgEntity.setFromUsername(paramConfig.currentUser.name);
                nWFTaskMsgEntity.setFromUsercode(paramConfig.currentUser.account);
                nWFTaskMsgEntity.setToUserid(item.id);
                nWFTaskMsgEntity.setToUsername(item.name);
                nWFTaskMsgEntity.setToUsercode(item.account);
                nWFTaskMsgEntity.setTitle(paramConfig.schemeName);
                nWFTaskMsgEntity.setContent("你有新的" + paramConfig.schemeName);
                nWFTaskMsgEntity.setNodeId(task.getNodeId());
                switch (task.getTaskType()) {
                    case 1:
                        nWFTaskMsgEntity.setContent(nWFTaskMsgEntity.getContent() + "需要审核，发起人" + paramConfig.createUser.name + "。");
                        break;
                    case 2:
                        nWFTaskMsgEntity.setContent(nWFTaskMsgEntity.getContent() + "需要查阅，发起人" + paramConfig.createUser.name + "。");
                        break;
                    case 3:
                        nWFTaskMsgEntity.setContent(nWFTaskMsgEntity.getContent() + "需要审核，来自加签，发起人" + paramConfig.createUser.name + "。");
                        break;
                    case 4: {
                        NwfTaskMsg nWFTaskMsgEntity2 = nWFTaskMsgEntity;
                        nWFTaskMsgEntity2.setContent(nWFTaskMsgEntity2.getContent() + "的" + task.getNodeName() + "需要创建，发起人" + paramConfig.createUser.name + "。");
                        break;
                    }
                    case 5:
                        nWFTaskMsgEntity.setContent(nWFTaskMsgEntity.getContent() + "需要重新创建。");
                        break;
                    case 6:
                        nWFTaskMsgEntity.setContent(nWFTaskMsgEntity.getContent() + "需要重新创建。");
                        break;
                }
                list.add(nWFTaskMsgEntity);
            }
        }
        return list;
    }

    private void _triggerMethod(NwfLineInfo line, String taskId, String nodeName, String code, NwfEngineParamConfig paramConfig) {
        switch (line.operationType) {
            case "sql":
                if (StringUtils.isNotEmpty(line.dbId) && StringUtils.isNotEmpty(line.strSql)) {
                    String strSql = line.strSql.replace("{processId}", "#{processId}");
                    strSql = strSql.replace("{userId}", "#{userId}");
                    strSql = strSql.replace("{userAccount}", "#{userAccount}");
                    strSql = strSql.replace("{companyId}", "#{companyId}");
                    strSql = strSql.replace("{departmentId}", "#{departmentId}");
                    strSql = strSql.replace("{code}", "#{code}");

                    Map<String, Object> param = new HashMap<>();
                    param.put("processId", paramConfig.processId);
                    param.put("userId", paramConfig.currentUser.id);
                    param.put("userAccount", paramConfig.currentUser.account);
                    param.put("companyId", paramConfig.currentUser.companyId);
                    param.put("departmentId", paramConfig.currentUser.departmentId);
                    param.put("code", code);

                    formDbTableService.excuteSqlWithParams(line.dbId, strSql, param);
                }
                break;
            case "interface":
                if (StringUtils.isNotEmpty(line.strInterface)) {
                    Map<String, Object> postData = new HashMap<>();
                    postData.put("processId", paramConfig.processId);
                    postData.put("userId", paramConfig.currentUser.id);
                    postData.put("userAccount", paramConfig.currentUser.account);
                    postData.put("companyId", paramConfig.currentUser.companyId);
                    postData.put("departmentId", paramConfig.currentUser.departmentId);
                    postData.put("code", code);

//                    HttpMethods.Post(line.strInterface, postData.ToJson()); //TODO 暂不实现接口
                }
                break;
            case "ioc":
                if (StringUtils.isNotEmpty(line.iocName)) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("processId", paramConfig.processId);
                    params.put("taskId", taskId);
                    params.put("nodeName", nodeName);
                    params.put("code", code);
                    params.put("userId", paramConfig.currentUser.id);
                    params.put("userAccount", paramConfig.currentUser.account);
                    params.put("userName", paramConfig.currentUser.name);
                    params.put("companyId", paramConfig.currentUser.companyId);
                    params.put("departmentId", paramConfig.currentUser.departmentId);

                    ReflectionUtils.quickInvoke(line.iocNameR, params);
                }
                break;
        }
    }

    private void _triggerMethod(NwfNodeInfo node, String taskId, String nodeName, String childProcessId, NwfEngineParamConfig paramConfig) {
        switch (node.operationType) {
            case "sql":
                if (StringUtils.isNotEmpty(node.dbId) && StringUtils.isNotEmpty(node.strSql)) {
                    String strSql = node.strSql.replace("{processId}", "#{processId}");
                    strSql = strSql.replace("{userId}", "#{userId}");
                    strSql = strSql.replace("{userAccount}", "#{userAccount}");
                    strSql = strSql.replace("{companyId}", "#{companyId}");
                    strSql = strSql.replace("{departmentId}", "#{departmentId}");
                    strSql = strSql.replace("{childProcessId}", "#{childProcessId}");

                    Map<String, Object> param = new HashMap<>();
                    param.put("processId", paramConfig.processId);
                    param.put("userId", paramConfig.currentUser.id);
                    param.put("userAccount", paramConfig.currentUser.account);
                    param.put("companyId", paramConfig.currentUser.companyId);
                    param.put("departmentId", paramConfig.currentUser.departmentId);
                    param.put("childProcessId", childProcessId);

                    formDbTableService.excuteSqlWithParams(node.dbId, strSql, param);
                }
                break;
            case "interface":
                if (StringUtils.isNotEmpty(node.strInterface)) {
                    Map<String, Object> postData = new HashMap<>();
                    postData.put("processId", paramConfig.processId);
                    postData.put("userId", paramConfig.currentUser.id);
                    postData.put("userAccount", paramConfig.currentUser.account);
                    postData.put("companyId", paramConfig.currentUser.companyId);
                    postData.put("departmentId", paramConfig.currentUser.departmentId);
                    postData.put("childProcessId", childProcessId);
//                    HttpMethods.Post(node.strInterface, postData.ToJson());//TODO 暂不实现接口
                }
                break;
            case "ioc":
                if (StringUtils.isNotEmpty(node.iocName)) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("processId", paramConfig.processId);
                    params.put("taskId", taskId);
                    params.put("nodeName", nodeName);
                    params.put("childProcessId", childProcessId);
                    params.put("userId", paramConfig.currentUser.id);
                    params.put("userAccount", paramConfig.currentUser.account);
                    params.put("userName", paramConfig.currentUser.name);
                    params.put("companyId", paramConfig.currentUser.companyId);
                    params.put("departmentId", paramConfig.currentUser.departmentId);

                    ReflectionUtils.quickInvoke(node.iocName, params);
                }
                break;
        }
    }

    private void _triggerMethod(NwfCloseDo closeDo, String code, NwfEngineParamConfig paramConfig) {
        switch (closeDo.closeDoType) {
            case "sql":
                if (StringUtils.isNotEmpty(closeDo.closeDoDbId) && StringUtils.isNotEmpty(closeDo.closeDoSql)) {
                    String strSql = closeDo.closeDoSql.replace("{processId}", "#{processId}");
                    strSql = strSql.replace("{userId}", "#{userId}");
                    strSql = strSql.replace("{userAccount}", "#{userAccount}");
                    strSql = strSql.replace("{companyId}", "#{companyId}");
                    strSql = strSql.replace("{departmentId}", "#{departmentId}");
                    strSql = strSql.replace("{code}", "#{code}");

                    Map<String, Object> param = new HashMap<>();
                    param.put("processId", paramConfig.processId);
                    param.put("userId", paramConfig.currentUser.id);
                    param.put("userAccount", paramConfig.currentUser.account);
                    param.put("companyId", paramConfig.currentUser.companyId);
                    param.put("departmentId", paramConfig.currentUser.departmentId);
                    param.put("code", code);

                    formDbTableService.excuteSqlWithParams(closeDo.closeDoDbId, strSql, param);
                }
                break;
            case "ioc":
                if (StringUtils.isNotEmpty(closeDo.closeDoIocName)) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("processId", paramConfig.processId);
                    params.put("code", code);
                    params.put("userId", paramConfig.currentUser.id);
                    params.put("userAccount", paramConfig.currentUser.account);
                    params.put("userName", paramConfig.currentUser.name);
                    params.put("companyId", paramConfig.currentUser.companyId);
                    params.put("departmentId", paramConfig.currentUser.departmentId);

                    ReflectionUtils.quickInvoke(closeDo.closeDoIocName, params);

                }
                break;
            case "interface":
                if (StringUtils.isNotEmpty(closeDo.closeDoInterface)) {

                    Map<String, Object> postData = new HashMap<>();
                    postData.put("processId", paramConfig.processId);
                    postData.put("userId", paramConfig.currentUser.id);
                    postData.put("userAccount", paramConfig.currentUser.account);
                    postData.put("companyId", paramConfig.currentUser.companyId);
                    postData.put("departmentId", paramConfig.currentUser.departmentId);
                    postData.put("code", code);

//                    HttpMethods.Post(closeDo.F_CloseDoInterface, postData.ToJson());//TODO 暂不实现接口
                }
                break;
        }
    }

    private void _triggerMethodR(NwfLineInfo line, String taskId, String nodeName, NwfEngineParamConfig paramConfig) {
        switch (line.operationType) {
            case "sql":
                if (StringUtils.isNotEmpty(line.dbId) && StringUtils.isNotEmpty(line.strSqlR)) {
                    String strSql = line.strSqlR.replace("{processId}", "#{processId}");
                    strSql = strSql.replace("{userId}", "#{userId}");
                    strSql = strSql.replace("{userAccount}", "#{userAccount}");
                    strSql = strSql.replace("{companyId}", "#{companyId}");
                    strSql = strSql.replace("{departmentId}", "#{departmentId}");
                    strSql = strSql.replace("{code}", "#{code}");

                    Map<String, Object> param = new HashMap<>();
                    param.put("processId", paramConfig.processId);
                    param.put("userId", paramConfig.currentUser.id);
                    param.put("userAccount", paramConfig.currentUser.account);
                    param.put("companyId", paramConfig.currentUser.companyId);
                    param.put("departmentId", paramConfig.currentUser.departmentId);
                    param.put("code", "RevokeAudit");

                    formDbTableService.excuteSqlWithParams(line.dbId, strSql, param);
                }
                break;
            case "interface":
                if (StringUtils.isNotEmpty(line.strInterfaceR)) {
                    Map<String, Object> postData = new HashMap<>();
                    postData.put("processId", paramConfig.processId);
                    postData.put("userId", paramConfig.currentUser.id);
                    postData.put("userAccount", paramConfig.currentUser.account);
                    postData.put("companyId", paramConfig.currentUser.companyId);
                    postData.put("departmentId", paramConfig.currentUser.departmentId);
                    postData.put("code", "RevokeAudit");

//                    HttpMethods.Post(line.strInterfaceR, postData.ToJson());//TODO 暂不实现接口
                }
                break;
            case "ioc":
                if (StringUtils.isNotEmpty(line.iocNameR)) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("processId", paramConfig.processId);
                    params.put("taskId", taskId);
                    params.put("nodeName", nodeName);
                    params.put("code", "RevokeAudit");
                    params.put("userId", paramConfig.currentUser.id);
                    params.put("userAccount", paramConfig.currentUser.account);
                    params.put("userName", paramConfig.currentUser.name);
                    params.put("companyId", paramConfig.currentUser.companyId);
                    params.put("departmentId", paramConfig.currentUser.departmentId);

                    ReflectionUtils.quickInvoke(line.iocNameR, params);
                }
                break;
        }
    }

    private List<NwfConfluence> _clearConfluence(List<NwfNodeInfo> nodeList, List<NwfTask> closeTaskList, String nodeId, String processId, int state, NwfIEngine nWFIEngine) {
        List<NwfConfluence> list = new ArrayList<>();
        for (NwfNodeInfo node : nodeList) {
            if (!(node.type.equals("confluencenode"))) {
                continue;
            }
            NwfConfluence entity = new NwfConfluence();
            entity.setFromNodeId(nodeId);
            entity.setProcessId(processId);
            entity.setNodeId(node.id);
            entity.setState(state);
            entity.setIsClear(false);
            if (node.confluenceRes != 0) {
                entity.confluenceRes = node.confluenceRes;
                entity.isClear = true;
                Map<String, String> hasMap = new HashMap<>();
                for (NwfTask task : taskService.getUnFinishTaskList(processId)) {
                    if (!task.getNodeId().equals(nodeId)) {
                        if (hasMap.containsKey(task.getNodeId())) {
                            task.setIsFinished(2);
                            closeTaskList.add(task);
                        } else if (nWFIEngine.isToNode(task.getNodeId(), node.id)) {
                            task.setIsFinished(2);
                            closeTaskList.add(task);
                        }
                    }
                }
            }
            entity = entity.create();
            list.add(entity);
        }
        return list;
    }

    private void _sendMsg(List<NwfTaskMsg> taskMsgList, NwfIEngine nWFIEngine) {
        if (nWFIEngine == null) {
            return;
        }
        for (NwfTaskMsg taskMsg : taskMsgList) {
            NwfNodeInfo nodeInfo = nWFIEngine.getNode(taskMsg.NodeId);
            if (StringUtils.isNotEmpty(nodeInfo.notice)) {
                SysUser userEntity = userService.findById(taskMsg.getToUserid());
                List<SysUser> msgUserList = new ArrayList<>();
                msgUserList.add(userEntity);
//                lR_StrategyInfoIBLL.sendMessage(nodeInfo.notice, taskMsg.getContent(), msgUserList.ToJson());   //TODO 发送通知
            }
        }
    }

    private void _autoAuditFlow(List<NwfTask> taskList, NwfIEngine nWFIEngine, SysUser userInfo) {
        for (NwfTask task : taskList) {
            NwfNodeInfo node = nWFIEngine.getNode(task.getNodeId());
            NwfUserInfo user = null;
            if (task.userInfoList != null && task.userInfoList.stream().filter(t -> t.noPeople != null && t.noPeople).count() > 0 && node.noPeopleGz == 2) {
                auditFlow("agree", "同意", nWFIEngine.getConfig().getProcessId(), task.getId(), "无审核人跳过", null, "", "", userInfo);
            } else {
                if (!(node.type.equals("stepnode")) || StringUtils.isEmpty(node.agreeGz)) {
                    continue;
                }
                String[] array = node.agreeGz.split(",");
                boolean flag = false;
                String[] array2 = array;
                for (String item : array2) {
                    switch (item) {
                        case "1": {
                            String createUserId = nWFIEngine.getConfig().createUser.id;
                            Optional<NwfUserInfo> userOption = task.userInfoList.stream().filter(t -> t.id.equals(createUserId) && t.mark == 0).findFirst();
                            if (userOption.isPresent()) {
                                user = userOption.get();
                                flag = true;
                            }
                            break;
                        }
                        case "2":
                            Optional<NwfUserInfo> userOption = task.userInfoList.stream().filter(t -> t.id.equals(userInfo.getId()) && t.mark == 0).findFirst();
                            if (userOption.isPresent()) {
                                user = userOption.get();
                                flag = true;
                            }
                            if (user != null) {
                                flag = true;
                            }
                            break;
                        case "3": {
                            List<NwfTaskLog> logList = taskService.getLogList(nWFIEngine.getConfig().processId);
                            if (logList.size() <= 0) {
                                break;
                            }
                            for (NwfUserInfo taskUserItem : task.userInfoList) {
                                long count = logList.stream().filter(t -> t.getCreateUserid().equals(taskUserItem.id) && t.getOperationCode().equals("agree")).count();
                                if (count > 0) {
                                    SysUser taskUserEntity = userService.findById(taskUserItem.id);
                                    user = new NwfUserInfo();
                                    user.id = taskUserEntity.getId();
                                    user.account = taskUserEntity.getUserName();
                                    user.name = taskUserEntity.getRealName();

                                    flag = true;
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    if (flag) {
                        SysUser _userInfo = new SysUser();
                        _userInfo.setId(user.getId());
                        _userInfo.setUserName(user.getAccount());
                        _userInfo.setRealName(user.getName());

                        auditFlow("agree", "同意", nWFIEngine.getConfig().processId, task.getId(), "系统自动审核", null, "", "", _userInfo);
                        break;
                    }
                }
                user = null;
            }
        }
    }

    public Map<String, List<NwfUserInfo>> getNextAuditors(String code, String processId, String taskId, String nodeId, String operationCode, SysUser userInfo) {
        Map<String, List<NwfUserInfo>> res = new HashMap<>();
        NwfIEngine nWFIEngine = _bootstraper(code, processId, taskId, userInfo);
        NwfNodeInfo nodeInfo = nWFIEngine.getNode(nodeId);
        for (NwfNodeInfo item : nWFIEngine.getNextTaskNode(nodeInfo, operationCode, true, new ArrayList<>())) {
            if ((item.type.equals("stepnode") || item.type.equals("auditornode") || item.type.equals("childwfnode")) && !res.containsKey(item.id)) {
                res.put(item.id, _getNodeAuditors(item.auditors, item, nWFIEngine.getConfig()));
            }
        }
        return res;
    }

    public NwfProcessDetailsModel getProcessDetails(String processId, String taskId, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, taskId, userInfo);
        NwfProcessDetailsModel nWFProcessDetailsModel = new NwfProcessDetailsModel();
        nWFProcessDetailsModel.setScheme(nWFIEngine.getScheme());
        nWFProcessDetailsModel.setCurrentNodeIds(taskService.getCurrentNodeIds(processId));
        nWFProcessDetailsModel.setTaskLogList(taskService.getLogList(processId));
        nWFProcessDetailsModel.setParentProcessId(nWFIEngine.getConfig().parentProcessId);
        nWFProcessDetailsModel.setIsFinished(findById(processId).getIsFinished());
        if (StringUtils.isEmpty(taskId)) {
            nWFProcessDetailsModel.setCurrentNodeId(nWFIEngine.getStartNode().id);
        } else {
            NwfTask nWFTaskEntity = taskService.getEntity(taskId);
            if (nWFTaskEntity != null) {
                if (StringUtils.isNotEmpty(nWFTaskEntity.getChildProcessId())) {
                    nWFProcessDetailsModel.setChildProcessId(nWFTaskEntity.getChildProcessId());
                    nWFProcessDetailsModel.setCurrentNodeIds(taskService.getCurrentNodeIds(nWFTaskEntity.getChildProcessId()));
                    nWFProcessDetailsModel.setTaskLogList(taskService.getLogList(nWFTaskEntity.getChildProcessId()));
                }
                nWFProcessDetailsModel.setCurrentNodeId(nWFTaskEntity.getNodeId());
            }
        }
        return nWFProcessDetailsModel;
    }

    public NwfProcessDetailsModel getChildProcessDetails(String processId, String taskId, String schemeCode, String nodeId, SysUser userInfo) {
        NwfProcessDetailsModel nWFProcessDetailsModel = new NwfProcessDetailsModel();
        Map<String, Object> param = new HashMap<>();
        param.put("parentProcessId", processId);
        param.put("parentNodeId", nodeId);
        List<NwfProcess> list = processDao.findAll(param);
        if (CollectionUtils.isEmpty(list)) {
            NwfIEngine nWFIEngine2 = _bootstraper(schemeCode, "", "", userInfo);
            nWFProcessDetailsModel.setScheme(nWFIEngine2.getScheme());
        } else {
            NwfProcess entity = list.get(0);
            NwfIEngine nWFIEngine = _bootstraper("", entity.getId(), "", userInfo);
            nWFProcessDetailsModel.setScheme(nWFIEngine.getScheme());
            nWFProcessDetailsModel.setCurrentNodeIds(taskService.getCurrentNodeIds(entity.getId()));
            nWFProcessDetailsModel.setTaskLogList(taskService.getLogList(entity.getId()));
            nWFProcessDetailsModel.setChildProcessId(entity.getId());
        }
        return nWFProcessDetailsModel;
    }

    public void saveDraft(String processId, String schemeCode, SysUser userInfo) {
        if (findById(processId) == null) {
            NwfSchemeinfo schemeInfo = schemeService.getInfoEntityByCode(schemeCode);
            NwfProcess nWFProcessEntity = new NwfProcess();
            nWFProcessEntity.setId(processId);
            nWFProcessEntity.setCode("P" + IdGenerator.next("process", 6));
            nWFProcessEntity.setSchemeCode(schemeCode);
            nWFProcessEntity.setSchemeName(schemeInfo.getName());
            nWFProcessEntity.setEnabledMark(2);
            nWFProcessEntity.setIsAgain(0);
            nWFProcessEntity.setIsFinished(0);
            nWFProcessEntity.setIsChild(0);
            nWFProcessEntity.setIsStart(0);
            nWFProcessEntity.setCreateUserid(userInfo.getId());
            nWFProcessEntity.setCreateUsername(userInfo.getRealName());

            nWFProcessEntity = nWFProcessEntity.create();
            processDao.save(nWFProcessEntity);
        }
    }

    public void deleteDraft(String processId, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, "", userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        com.open.capacity.workflow3.engine.NwfScheme scheme = nWFIEngine.getSchemeObj();
        delete(processId);
        _triggerMethod(scheme.closeDo, "3", nWFEngineParamConfig);
    }

    @Override
    @Transactional
    public void createFlow(String schemeCode, String processId, String processTitle, Integer processLevel, String auditors, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper(schemeCode, processId, "", userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        nWFEngineParamConfig.auditers = auditors;
        NwfNodeInfo nodeInfo = nWFIEngine.getStartNode();
        List<NwfLineInfo> lineList = new ArrayList<>();
        List<NwfNodeInfo> list = nWFIEngine.getNextTaskNode(nodeInfo, "agree", false, lineList);
        List<NwfTask> taskList = _createTask(list, nodeInfo, nWFEngineParamConfig);
        List<NwfTaskMsg> taskMsgList = _createTaskMsg(taskList, nWFEngineParamConfig);

        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(nWFEngineParamConfig.processId);
        nWFProcessEntity.setSchemeId(nWFEngineParamConfig.schemeId);
        nWFProcessEntity.setSchemeCode(nWFEngineParamConfig.schemeCode);
        nWFProcessEntity.setSchemeName(nWFEngineParamConfig.schemeName);
        nWFProcessEntity.setProcessLevel(processLevel);
        nWFProcessEntity.setEnabledMark(1);
        nWFProcessEntity.setIsAgain(0);
        nWFProcessEntity.setIsFinished(0);
        nWFProcessEntity.setIsChild(0);
        nWFProcessEntity.setIsStart(0);
        nWFProcessEntity.setCreateUserid(nWFEngineParamConfig.currentUser.id);
        nWFProcessEntity.setCreateUsername(nWFEngineParamConfig.currentUser.name);


        if (StringUtils.isNotEmpty(processTitle)) {
            nWFProcessEntity.setProcessTitle(processTitle);
        } else {
            nWFProcessEntity.setProcessTitle(nWFEngineParamConfig.schemeName);
        }
        if (nWFEngineParamConfig.getState() == 1) {
            nWFProcessEntity.setIsAgain(1);
        } else if (nWFEngineParamConfig.getState() == 2) {
            nWFProcessEntity.setIsFinished(1);
        }
        nWFProcessEntity = nWFProcessEntity.create();
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();

        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("create");
        nWFTaskLogEntity.setOperationName("创建流程");
        nWFTaskLogEntity.setNodeId(nodeInfo.id);
        nWFTaskLogEntity.setNodeName(nodeInfo.name);
        nWFTaskLogEntity.setTaskType(0);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());

        nWFTaskLogEntity = nWFTaskLogEntity.create();
        save(nWFProcessEntity, taskList, taskMsgList, nWFTaskLogEntity);
        for (NwfLineInfo line : lineList) {
            _triggerMethod(line, "", nodeInfo.name, "create", nWFEngineParamConfig);
        }
        _sendMsg(taskMsgList, nWFIEngine);
        for (NwfTask taskItem : taskList) {
            if (taskItem.getTaskType() == 4) {
                NwfNodeInfo cNodeInfo = nWFIEngine.getNode(taskItem.getNodeId());
                _triggerMethod(cNodeInfo, taskItem.getId(), cNodeInfo.name, taskItem.getChildProcessId(), nWFEngineParamConfig);
            }
        }
        _autoAuditFlow(taskList, nWFIEngine, userInfo);
    }

    @Override
    @Transactional
    public void createChildFlow(String schemeCode, String processId, String parentProcessId, String parentTaskId, SysUser userInfo) {
        NwfTask pTaskEntity = taskService.getEntity(parentTaskId);
        NwfIEngine pNwfIEngine = _bootstraper("", parentProcessId, parentTaskId, userInfo);
        NwfEngineParamConfig pNwfEngineParamConfig = pNwfIEngine.getConfig();
        NwfNodeInfo pNodeInfo = pNwfIEngine.getNode(pTaskEntity.getNodeId());
        if (findById(processId) != null) {
            schemeCode = null;
        }
        NwfIEngine nWFIEngine = _bootstraper(schemeCode, processId, "", userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        NwfNodeInfo nodeInfo = nWFIEngine.getStartNode();
        List<NwfLineInfo> lineList = new ArrayList<>();
        List<NwfNodeInfo> list = nWFIEngine.getNextTaskNode(nodeInfo, "agree", false, lineList);
        List<NwfTask> taskList = _createTask(list, nodeInfo, nWFEngineParamConfig);
        List<NwfTaskMsg> taskMsgList = _createTaskMsg(taskList, nWFEngineParamConfig);
        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(nWFEngineParamConfig.processId);
        nWFProcessEntity.setCode("P" + IdGenerator.next("process", 6));
        nWFProcessEntity.setSchemeId(nWFEngineParamConfig.schemeId);
        nWFProcessEntity.setSchemeCode(nWFEngineParamConfig.schemeCode);
        nWFProcessEntity.setSchemeName(nWFEngineParamConfig.schemeName);
        nWFProcessEntity.setProcessTitle(pNwfEngineParamConfig.schemeName + "【子流程】");
        nWFProcessEntity.setEnabledMark(1);
        nWFProcessEntity.setIsAgain(0);
        nWFProcessEntity.setIsFinished(0);
        nWFProcessEntity.setIsChild(1);
        nWFProcessEntity.setIsAsyn((!(pNodeInfo.childType.equals("1"))) ? 1 : 0);
        nWFProcessEntity.setIsStart(0);
        nWFProcessEntity.setCreateUserid(nWFEngineParamConfig.currentUser.id);
        nWFProcessEntity.setCreateUsername(nWFEngineParamConfig.currentUser.name);
        nWFProcessEntity.setParentProcessId(parentProcessId);
        nWFProcessEntity.setParentTaskId(parentTaskId);
        nWFProcessEntity.setParentNodeId(pTaskEntity.getNodeId());

        if (nWFEngineParamConfig.state == 1) {
            nWFProcessEntity.setIsAgain(1);
        } else if (nWFEngineParamConfig.state == 2) {
            nWFProcessEntity.setIsFinished(1);
        }
        nWFProcessEntity = nWFProcessEntity.create();
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("create");
        nWFTaskLogEntity.setOperationName("创建流程");
        nWFTaskLogEntity.setNodeId(nodeInfo.getId());
        nWFTaskLogEntity.setNodeName(nodeInfo.getName());
        nWFTaskLogEntity.setTaskType(0);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());

        nWFTaskLogEntity = nWFTaskLogEntity.create();
        List<NwfTaskRelation> pTaskUserList = taskService.getTaskUserList(parentTaskId);
        boolean isMyPTask = false;
        String pTaskUserId = userInfo.getId();
        Map<String, String> pTaskUserMap = new HashMap<>();
        for (NwfTaskRelation item2 : pTaskUserList) {
            if (item2.getUserid().equals(userInfo.getId())) {
                isMyPTask = true;
            }
            if (!pTaskUserMap.containsKey(userInfo.getId())) {
                pTaskUserMap.put(userInfo.getId(), "1");
            }
        }
        if (!isMyPTask) {
            for (SysUser item : getDelegateProcess(userInfo.getId())) {
                if (pTaskUserMap.containsKey(item.getId())) {
                    pTaskUserId = item.getId();
                }
            }
        }
        NwfTaskLog pNwfTaskLogEntity = new NwfTaskLog();
        pNwfTaskLogEntity.setProcessId(parentProcessId);
        pNwfTaskLogEntity.setOperationCode((schemeCode == null) ? "againCreateChild" : "createChild");
        pNwfTaskLogEntity.setOperationName((schemeCode == null) ? "重新创建" : "创建子流程");
        pNwfTaskLogEntity.setNodeId(pTaskEntity.getNodeId());
        pNwfTaskLogEntity.setNodeName(pTaskEntity.getNodeName());
        pNwfTaskLogEntity.setPrevNodeId(pTaskEntity.getPrevNodeId());
        pNwfTaskLogEntity.setPrevNodeName(pTaskEntity.getPrevNodeName());
        pNwfTaskLogEntity.setTaskId(parentTaskId);
        pNwfTaskLogEntity.setTaskType(4);
        pNwfTaskLogEntity.setCreateUserid(userInfo.getId());
        pNwfTaskLogEntity.setCreateUsername(userInfo.getRealName());

        if (!userInfo.getId().equals(pTaskUserId)) {
            nWFTaskLogEntity.setTaskUserid(pTaskUserId);
            nWFTaskLogEntity.setTaskUsername(userService.findById(pTaskUserId).getRealName());
        }
        pNwfTaskLogEntity = pNwfTaskLogEntity.create();
        String finalPTaskUserId = pTaskUserId;
        Optional<NwfTaskRelation> relationOptional = pTaskUserList.stream().filter(t -> t.getUserid().equals(finalPTaskUserId)).findFirst();
        NwfTaskRelation nWFTaskRelationEntity = relationOptional.get();
        nWFTaskRelationEntity.setCreateTime(new Date());
        nWFTaskRelationEntity.setResult(4);
        NwfProcess pNwfProcess = new NwfProcess();
        pNwfProcess.setId(pNwfEngineParamConfig.processId);
        pNwfProcess.setIsStart(1);

        List<NwfLineInfo> pLineList = new ArrayList<>();
        List<NwfTask> pTaskList = new ArrayList<>();
        List<NwfTaskMsg> pTaskMsgList = new ArrayList<>();
        if (pNodeInfo.childType.equals("1") && nWFProcessEntity.getIsFinished() == 1) {
            List<NwfNodeInfo> pList = pNwfIEngine.getNextTaskNode(pNodeInfo, "agree", false, pLineList);
            pTaskList = _createTask(pList, pNodeInfo, pNwfEngineParamConfig);
            pTaskMsgList = _createTaskMsg(pTaskList, pNwfEngineParamConfig);
            NwfTaskMsg nWFTaskMsgEntity = new NwfTaskMsg();
            nWFTaskMsgEntity.setProcessId(pNwfEngineParamConfig.processId);
            nWFTaskMsgEntity.setFromUserid(pNwfEngineParamConfig.currentUser.id);
            nWFTaskMsgEntity.setFromUsercode(pNwfEngineParamConfig.currentUser.account);
            nWFTaskMsgEntity.setFromUsername(pNwfEngineParamConfig.currentUser.name);
            nWFTaskMsgEntity.setToUserid(pNwfEngineParamConfig.createUser.id);
            nWFTaskMsgEntity.setToUsercode(pNwfEngineParamConfig.createUser.account);
            nWFTaskMsgEntity.setToUsername(pNwfEngineParamConfig.createUser.name);
            nWFTaskMsgEntity.setTitle(pNwfEngineParamConfig.schemeName);
            nWFTaskMsgEntity.setContent("你的流程有状态的更新：" + pNwfEngineParamConfig.currentUser.name + "发起子流程【" + nWFEngineParamConfig.schemeName + "】");
            nWFTaskMsgEntity.NodeId = pNwfIEngine.getStartNode().id;
            NwfTaskMsg pNwfTaskMsgEntity = nWFTaskMsgEntity;
            pNwfTaskMsgEntity = pNwfTaskMsgEntity.create();
            pTaskMsgList.add(pNwfTaskMsgEntity);
        }
        pTaskEntity.setIsFinished(1);
        pTaskEntity.setUpdateTime(new Date());
        pTaskEntity.setCreateUserid(userInfo.getId());
        pTaskEntity.setCreateUsername(userInfo.getRealName());
        save(pNwfTaskLogEntity, nWFTaskRelationEntity, pTaskEntity, pNwfProcess, pTaskList, pTaskMsgList, nWFProcessEntity, taskList, taskMsgList, nWFTaskLogEntity);
        for (NwfLineInfo line2 : pLineList) {
            _triggerMethod(line2, "", pNodeInfo.name, "create", pNwfEngineParamConfig);
        }
        _sendMsg(pTaskMsgList, pNwfIEngine);
        for (NwfLineInfo line : lineList) {
            _triggerMethod(line, "", nodeInfo.name, "create", nWFEngineParamConfig);
        }
        _sendMsg(taskMsgList, nWFIEngine);
    }

    @Override
    @Transactional
    public void againCreateFlow(String processId, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, "", userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        NwfNodeInfo nodeInfo = nWFIEngine.getStartNode();
        NwfTask taskEntiy = taskService.getEntityByNodeId(nodeInfo.id, processId);
        Assert.notNull(taskEntiy, "找不到对应流程任务");
        Assert.isTrue(taskEntiy.getIsFinished() == 0, "该任务已经结束！");
        taskEntiy.setUpdateTime(new Date());
        taskEntiy.setUpdateUserid(userInfo.getId());
        taskEntiy.setUpdateUsername(userInfo.getRealName());
        taskEntiy.setIsFinished(1);
        String taskUserId = userInfo.getId();
        List<NwfTaskRelation> taskUserList = taskService.getTaskUserList(taskEntiy.getId());
        boolean isMyTask = false;
        Map<String, String> taskUserMap = new HashMap<>();
        for (NwfTaskRelation item2 : taskUserList) {
            if (item2.getUserid().equals(userInfo.getId())) {
                isMyTask = true;
            }
            if (!taskUserMap.containsKey(userInfo.getId())) {
                taskUserMap.put(userInfo.getId(), "1");
            }
        }
        if (!isMyTask) {
            for (SysUser item : getDelegateProcess(userInfo.getId())) {
                if (taskUserMap.containsKey(item.getId())) {
                    taskUserId = item.getId();
                }
            }
        }
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("create");
        nWFTaskLogEntity.setOperationName("重新发起");
        nWFTaskLogEntity.setNodeId(nodeInfo.id);
        nWFTaskLogEntity.setNodeName(nodeInfo.name);
        nWFTaskLogEntity.setPrevNodeId(taskEntiy.getPrevNodeId());
        nWFTaskLogEntity.setPrevNodeName(taskEntiy.getPrevNodeName());
        nWFTaskLogEntity.setTaskId(taskEntiy.getId());
        nWFTaskLogEntity.setTaskType(5);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskLogEntity.setTaskUserid(userInfo.getId());
        nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());
        if (!userInfo.getId().equals(taskUserId)) {
            nWFTaskLogEntity.setTaskUserid(taskUserId);
            nWFTaskLogEntity.setTaskUsername(userService.findById(taskUserId).getRealName());
        }
        nWFTaskLogEntity = nWFTaskLogEntity.create();
        String finalTaskUserId = taskUserId;
        Optional<NwfTaskRelation> relationOptional = taskUserList.stream().filter(t -> t.getUserid().equals(finalTaskUserId)).findFirst();
        NwfTaskRelation nWFTaskRelationEntity = relationOptional.get();

        nWFTaskRelationEntity.setResult(1);
        List<NwfLineInfo> lineList = new ArrayList<>();
        List<NwfNodeInfo> list = nWFIEngine.getNextTaskNode(nodeInfo, "agree", false, lineList);
        List<NwfTask> taskList = _createTask(list, nodeInfo, nWFEngineParamConfig);
        List<NwfTaskMsg> taskMsgList = _createTaskMsg(taskList, nWFEngineParamConfig);
        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(nWFEngineParamConfig.processId);
        nWFProcessEntity.setIsAgain(0);
        if (nWFEngineParamConfig.state == 1) {
            nWFProcessEntity.setIsAgain(1);
        } else if (nWFEngineParamConfig.state == 2) {
            nWFProcessEntity.setIsFinished(1);
        }
        save(nWFTaskLogEntity, nWFTaskRelationEntity, taskEntiy, nWFProcessEntity, null, null, taskList, taskMsgList, null);
        for (NwfLineInfo line : lineList) {
            _triggerMethod(line, taskEntiy.getId(), nodeInfo.name, "", nWFEngineParamConfig);
        }
        _sendMsg(taskMsgList, nWFIEngine);
        for (NwfTask taskItem : taskList) {
            if (taskItem.getTaskType() == 4) {
                NwfNodeInfo cNodeInfo = nWFIEngine.getNode(taskItem.getNodeId());
                _triggerMethod(cNodeInfo, taskItem.getId(), cNodeInfo.name, taskItem.getChildProcessId(), nWFEngineParamConfig);
            }
        }
        _autoAuditFlow(taskList, nWFIEngine, userInfo);
    }

    @Override
    @Transactional
    public void auditFlow(String operationCode, String operationName, String processId, String taskId, String des, String auditors, String stamp, String signUrl, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, taskId, userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        nWFEngineParamConfig.auditers = auditors;
        NwfTask taskEntiy = taskService.getEntity(taskId);
        Assert.notNull(taskEntiy, "找不到对应流程任务");
        Assert.isTrue(taskEntiy.getIsFinished() == 0, "该任务已经结束！");
        taskEntiy.setUpdateTime(new Date());
        taskEntiy.setUpdateUserid(userInfo.getId());
        taskEntiy.setUpdateUsername(userInfo.getRealName());
        taskEntiy.setIsFinished(1);
        NwfNodeInfo nodeInfo = nWFIEngine.getNode(taskEntiy.getNodeId());
        String taskUserId = userInfo.getId();
        List<NwfTaskRelation> taskUserList = taskService.getTaskUserList(taskId);
        boolean isMyTask = false;
        Map<String, String> taskUserMap = new HashMap<>();
        for (NwfTaskRelation item2 : taskUserList) {
            if (item2.getUserid().equals(userInfo.getId())) {
                isMyTask = true;
            }
            if (!taskUserMap.containsKey(userInfo.getId())) {
                taskUserMap.put(userInfo.getId(), "1");
            }
        }
        if (!isMyTask) {
            for (SysUser item : getDelegateProcess(userInfo.getId())) {
                if (!taskUserMap.containsKey(item.getId())) {
                    taskUserId = item.getId();
                }
            }
        }
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode(operationCode);
        nWFTaskLogEntity.setOperationName(operationName);
        nWFTaskLogEntity.setNodeId(nodeInfo.getId());
        nWFTaskLogEntity.setNodeName(nodeInfo.getName());
        nWFTaskLogEntity.setPrevNodeId(taskEntiy.getPrevNodeId());
        nWFTaskLogEntity.setPrevNodeName(taskEntiy.getPrevNodeName());
        nWFTaskLogEntity.setDescription(des);
        nWFTaskLogEntity.setTaskId(taskId);
        nWFTaskLogEntity.setTaskType(1);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskLogEntity.setTaskUserid(userInfo.getId());
        nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());
        nWFTaskLogEntity.setStampImg(stamp);

        if (StringUtils.isNotEmpty(signUrl)) {
            SysFile imgEntity = new SysFile();
            imgEntity.setId(UUIDUtils.getOriginalUUIDWithoutBar());
            imgEntity.setName("sign");
            imgEntity.setExt(".png");
            imgEntity.setContext(signUrl);
            fileService.save(imgEntity); //保存签名图片
            nWFTaskLogEntity.setSignImg(imgEntity.getId());
        }
        if (!userInfo.getId().equals(taskUserId)) {
            nWFTaskLogEntity.setTaskUserid(taskUserId);
            nWFTaskLogEntity.setTaskUsername(userService.findById(taskUserId).getRealName());
        }
        nWFTaskLogEntity = nWFTaskLogEntity.create();
        NwfTaskMsg nWFTaskMsgEntity = new NwfTaskMsg();
        nWFTaskMsgEntity.setProcessId(nWFEngineParamConfig.processId);
        nWFTaskMsgEntity.setFromUserid(nWFEngineParamConfig.currentUser.id);
        nWFTaskMsgEntity.setFromUsercode(nWFEngineParamConfig.currentUser.account);
        nWFTaskMsgEntity.setFromUsername(nWFEngineParamConfig.currentUser.name);
        nWFTaskMsgEntity.setToUserid(nWFEngineParamConfig.createUser.id);
        nWFTaskMsgEntity.setToUsercode(nWFEngineParamConfig.createUser.account);
        nWFTaskMsgEntity.setToUsername(nWFEngineParamConfig.createUser.name);
        nWFTaskMsgEntity.setTitle(nWFEngineParamConfig.schemeName);
        nWFTaskMsgEntity.setContent("你的流程有状态的更新：" + nWFEngineParamConfig.currentUser.name + operationName);
        nWFTaskMsgEntity.setNodeId(nWFIEngine.getStartNode().id);
        nWFTaskMsgEntity = nWFTaskMsgEntity.create();

        String finalTaskUserId = taskUserId;
        Optional<NwfTaskRelation> relationOptional = taskUserList.stream().filter(t -> t.getUserid().equals(finalTaskUserId)).findFirst();
        NwfTaskRelation nWFTaskRelationEntity;
        if (relationOptional.isPresent()) {
            nWFTaskRelationEntity = relationOptional.get();
        } else {
            nWFTaskRelationEntity = taskUserList.get(0);
        }
        nWFTaskRelationEntity.setCreateTime(new Date());
        if (nodeInfo.isAllAuditor.equals("2")) {
            if (operationCode.equals("agree")) {
                nWFTaskRelationEntity.setResult(1);
                if (taskUserList.stream().filter(t -> t.getResult() == 0).count() > 0) {
                    List<NwfTaskRelation> taskUserUpdateList2 = new ArrayList<>();
                    taskUserUpdateList2.add(nWFTaskRelationEntity);
                    if (nodeInfo.auditorType.equals("2")) {
                        NwfTaskRelation nWFTaskRelationEntity3 = taskUserList.get(nWFTaskRelationEntity.getSort());
                        nWFTaskRelationEntity3.setMark(0);
                        taskUserUpdateList2.add(nWFTaskRelationEntity3);
                    }
                    save(nWFTaskLogEntity, taskUserUpdateList2, nWFTaskMsgEntity);
                    return;
                }
            } else if (nodeInfo.auditExecutType.equals("2")) {
                if (operationCode.equals("disagree")) {
                    nWFTaskRelationEntity.setResult(2);
                } else {
                    nWFTaskRelationEntity.setResult(4);
                }
                if (taskUserList.stream().filter(t -> t.getResult() == 0).count() > 0) {
                    List<NwfTaskRelation> taskUserUpdateList = new ArrayList<>();
                    taskUserUpdateList.add(nWFTaskRelationEntity);
                    if (nodeInfo.auditorType.equals("2")) {
                        NwfTaskRelation nWFTaskRelationEntity2 = taskUserList.get(nWFTaskRelationEntity.getSort());
                        nWFTaskRelationEntity2.setMark(0);
                        taskUserUpdateList.add(nWFTaskRelationEntity2);
                    }
                    save(nWFTaskLogEntity, taskUserUpdateList, nWFTaskMsgEntity);
                    return;
                }
            } else {
                operationCode = "disagree";
                nWFTaskRelationEntity.setResult(2);
            }
        } else if (operationCode.equals("agree")) {
            nWFTaskRelationEntity.setResult(1);
        } else if (operationCode.equals("disagree")) {
            nWFTaskRelationEntity.setResult(2);
        } else {
            nWFTaskRelationEntity.setResult(4);
        }
        List<NwfLineInfo> lineList = new ArrayList<>();
        List<NwfNodeInfo> list = nWFIEngine.getNextTaskNode(nodeInfo, operationCode, false, lineList);
        int state = 0;
        if (operationCode.equals("agree")) {
            state = 1;
        }
        List<NwfTask> closeTaskList = new ArrayList<>();
        List<NwfConfluence> confluenceList = _clearConfluence(list, closeTaskList, nodeInfo.id, nWFEngineParamConfig.processId, state, nWFIEngine);
        List<NwfTask> taskList = _createTask(list, nodeInfo, nWFEngineParamConfig);
        List<NwfTaskMsg> taskMsgList = _createTaskMsg(taskList, nWFEngineParamConfig);
        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(nWFEngineParamConfig.processId);
        nWFProcessEntity.setIsStart(1);

        if (nWFEngineParamConfig.state == 1) {
            nWFProcessEntity.setIsAgain(1);
        } else if (nWFEngineParamConfig.state == 2) {
            nWFProcessEntity.setIsFinished(1);
        }
        List<NwfLineInfo> pLineList = new ArrayList<>();
        List<NwfTask> pTaskList = new ArrayList<>();
        List<NwfTaskMsg> pTaskMsgList = new ArrayList<>();
        NwfEngineParamConfig pNwfEngineParamConfig = null;
        NwfNodeInfo pNodeInfo = null;
        NwfIEngine pNwfIEngine = null;
        NwfProcess pNwfProcess = null;
        if (nWFEngineParamConfig.getIsChild() == 1) {
            pNwfIEngine = _bootstraper("", nWFEngineParamConfig.parentProcessId, nWFEngineParamConfig.parentTaskId, userInfo);
            pNwfEngineParamConfig = pNwfIEngine.getConfig();
            nWFTaskMsgEntity.setToUserid(pNwfEngineParamConfig.createUser.id);
            nWFTaskMsgEntity.setToUsername(pNwfEngineParamConfig.createUser.name);
            nWFTaskMsgEntity.setToUsercode(pNwfEngineParamConfig.createUser.account);
            nWFTaskMsgEntity.setTitle(pNwfEngineParamConfig.schemeName);
            nWFTaskMsgEntity.setContent("你的流程【子流程:" + nWFEngineParamConfig.schemeName + "】有状态的更新：" + nWFEngineParamConfig.currentUser.name + operationName);
            nWFTaskMsgEntity.NodeId = pNwfIEngine.getStartNode().id;
            if (findById(nWFEngineParamConfig.processId).getIsAsyn() == 0 && nWFEngineParamConfig.state == 2) {
                NwfTask pTaskEntity = taskService.getEntity(nWFEngineParamConfig.parentTaskId);
                pNodeInfo = pNwfIEngine.getNode(pTaskEntity.getNodeId());
                List<NwfNodeInfo> pList = pNwfIEngine.getNextTaskNode(pNodeInfo, "agree", false, pLineList);
                pTaskList = _createTask(pList, pNodeInfo, pNwfEngineParamConfig);
                pTaskMsgList = _createTaskMsg(pTaskList, pNwfEngineParamConfig);
                if (pNwfEngineParamConfig.state == 1) {
                    pNwfProcess = new NwfProcess();
                    pNwfProcess.setId(pNwfEngineParamConfig.processId);
                    pNwfProcess.setIsAgain(1);
                } else if (pNwfEngineParamConfig.state == 2) {
                    pNwfProcess = new NwfProcess();
                    pNwfProcess.setId(pNwfEngineParamConfig.processId);
                    pNwfProcess.setIsFinished(1);
                }
            }
            pTaskMsgList.add(nWFTaskMsgEntity);
        } else {
            taskMsgList.add(nWFTaskMsgEntity);
        }
        _sendMsg(pTaskMsgList, pNwfIEngine);
        _sendMsg(taskMsgList, nWFIEngine);
        List<NwfTask> nTaskList = new ArrayList<>();
        nTaskList.addAll(taskList);
        taskList.addAll(pTaskList);
        taskMsgList.addAll(pTaskMsgList);
        save(nWFTaskLogEntity, nWFTaskRelationEntity, taskEntiy, nWFProcessEntity, confluenceList, closeTaskList, taskList, taskMsgList, pNwfProcess);
        for (NwfLineInfo line2 : pLineList) {
            _triggerMethod(line2, "", pNodeInfo.name, "create", pNwfEngineParamConfig);
        }
        for (NwfLineInfo line : lineList) {
            _triggerMethod(line, taskId, nodeInfo.name, operationCode, nWFEngineParamConfig);
        }
        for (NwfTask taskItem : taskList) {
            if (taskItem.getTaskType() == 4) {
                NwfNodeInfo cNodeInfo = nWFIEngine.getNode(taskItem.getNodeId());
                if (cNodeInfo == null) {
                    cNodeInfo = pNwfIEngine.getNode(taskItem.getNodeId());
                    _triggerMethod(cNodeInfo, taskItem.getId(), cNodeInfo.name, taskItem.getChildProcessId(), pNwfEngineParamConfig);
                } else {
                    _triggerMethod(cNodeInfo, taskItem.getId(), cNodeInfo.name, taskItem.getChildProcessId(), nWFEngineParamConfig);
                }
            }
        }
        _autoAuditFlow(nTaskList, nWFIEngine, userInfo);
        _autoAuditFlow(pTaskList, pNwfIEngine, userInfo);
    }

    @Override
    @Transactional
    public void auditFlows(String operationCode, String taskIds, SysUser userInfo) {
        String[] array = taskIds.split(",");
        for (String taskId : array) {
            String operationName = ((operationCode.equals("agree")) ? "同意" : "不同意");
            NwfTask taskEntity = taskService.getEntity(taskId);
            if (taskEntity != null && taskEntity.getIsFinished() == 0 && taskEntity.getIsBatchAudit() == 1) {
                auditFlow(operationCode, operationName, taskEntity.getProcessId(), taskId, "批量审核", "{}", "", "", userInfo);
            }
        }
    }

    @Override
    @Transactional
    public void signFlow(String processId, String taskId, String userId, String des, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, taskId, userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        NwfTask taskEntiy = taskService.getEntity(taskId);
        Assert.notNull(taskEntiy, "找不到对应流程任务");
        Assert.isTrue(taskEntiy.getIsFinished() == 0, "该任务已经结束！");
        taskEntiy.setUpdateTime(new Date());
        taskEntiy.setUpdateUserid(userInfo.getId());
        taskEntiy.setUpdateUsername(userInfo.getRealName());
        taskEntiy.setIsFinished(1);
        String taskUserId = userInfo.getId();
        List<NwfTaskRelation> taskUserList = taskService.getTaskUserList(taskId);
        boolean isMyTask = false;
        Map<String, String> taskUserMap = new HashMap<>();
        for (NwfTaskRelation item2 : taskUserList) {
            if (item2.getUserid().equals(userInfo.getId())) {
                isMyTask = true;
            }
            if (!taskUserMap.containsKey(userInfo.getId())) {
                taskUserMap.put(userInfo.getId(), "1");
            }
        }
        if (!isMyTask) {
            for (SysUser item : getDelegateProcess(userInfo.getId())) {
                if (taskUserMap.containsKey(item.getId())) {
                    taskUserId = item.getId();
                }
            }
        }
        SysUser userEntity = userService.findById(userId);
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("sign");
        nWFTaskLogEntity.setOperationName("请求【" + userEntity.getRealName() + "】加签");
        nWFTaskLogEntity.setNodeId(taskEntiy.getNodeId());
        nWFTaskLogEntity.setNodeName(taskEntiy.getNodeName());
        nWFTaskLogEntity.setPrevNodeId(taskEntiy.getPrevNodeId());
        nWFTaskLogEntity.setPrevNodeName(taskEntiy.getPrevNodeName());
        nWFTaskLogEntity.setDescription(des);
        nWFTaskLogEntity.setTaskId(taskId);
        nWFTaskLogEntity.setTaskType(8);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskLogEntity.setTaskUserid(userInfo.getId());
        nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());

        if (!userInfo.getId().equals(taskUserId)) {
            nWFTaskLogEntity.setTaskUserid(taskUserId);
            nWFTaskLogEntity.setTaskUsername(userService.findById(taskUserId).getRealName());
        }
        nWFTaskLogEntity = nWFTaskLogEntity.create();
        NwfTaskMsg nWFTaskMsgEntity = new NwfTaskMsg();
        nWFTaskMsgEntity.setProcessId(nWFEngineParamConfig.processId);
        nWFTaskMsgEntity.setFromUserid(nWFEngineParamConfig.currentUser.id);
        nWFTaskMsgEntity.setFromUsercode(nWFEngineParamConfig.currentUser.account);
        nWFTaskMsgEntity.setFromUsername(nWFEngineParamConfig.currentUser.name);
        nWFTaskMsgEntity.setToUserid(nWFEngineParamConfig.createUser.id);
        nWFTaskMsgEntity.setToUsercode(nWFEngineParamConfig.createUser.account);
        nWFTaskMsgEntity.setToUsername(nWFEngineParamConfig.createUser.name);
        nWFTaskMsgEntity.setTitle(nWFEngineParamConfig.schemeName);
        nWFTaskMsgEntity.setContent("你的流程有状态的更新：" + nWFEngineParamConfig.currentUser.name + "加签");
        nWFTaskMsgEntity.setNodeId(nWFIEngine.getStartNode().id);
        nWFTaskMsgEntity = nWFTaskMsgEntity.create();

        String finalTaskUserId = taskUserId;
        NwfTaskRelation nWFTaskRelationEntity = taskUserList.stream().filter(t -> t.getUserid().equals(finalTaskUserId)).findFirst().get();
        nWFTaskRelationEntity.setCreateTime(new Date());
        nWFTaskRelationEntity.setResult(4);
        List<NwfTask> taskList = new ArrayList<>();
        nWFIEngine.getNode(taskEntiy.getNodeId());
        NwfTask nWFTaskEntity = new NwfTask();
        nWFTaskEntity = nWFTaskEntity.create();
        nWFTaskEntity.setProcessId(nWFEngineParamConfig.processId);
        nWFTaskEntity.setNodeId(taskEntiy.getNodeId());
        nWFTaskEntity.setNodeName(taskEntiy.getNodeName());
        nWFTaskEntity.setPrevNodeId(taskEntiy.getNodeId());
        nWFTaskEntity.setPrevNodeName(taskEntiy.getNodeName());
        nWFTaskEntity.setCreateUserid(userInfo.getId());
        nWFTaskEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskEntity.setTimeoutAction(taskEntiy.getTimeoutAction());
        nWFTaskEntity.setTimeoutInterval(taskEntiy.getTimeoutInterval());
        nWFTaskEntity.setTimeoutNotice(taskEntiy.getTimeoutNotice());
        nWFTaskEntity.setTimeoutStrategy(taskEntiy.getTimeoutStrategy());
        nWFTaskEntity.userInfoList = new ArrayList<>();
        NwfUserInfo user = new NwfUserInfo();
        user.id = userId;
        user.account = userEntity.getUserCode();
        user.name = userEntity.getRealName();
        nWFTaskEntity.userInfoList.add(user);
        nWFTaskEntity.setTaskType(3);
        if (StringUtils.isEmpty(taskEntiy.getFirstUserid())) {
            nWFTaskEntity.setFirstUserid(taskUserId);
        } else {
            nWFTaskEntity.setFirstUserid(taskEntiy.getFirstUserid());
        }
        taskList.add(nWFTaskEntity);
        List<NwfTaskMsg> taskMsgList = _createTaskMsg(taskList, nWFEngineParamConfig);
        List<NwfTaskMsg> pTaskMsgList = new ArrayList<>();
        NwfEngineParamConfig pNwfEngineParamConfig = null;
        NwfIEngine pNwfIEngine = null;
        if (nWFEngineParamConfig.getIsChild() == 1) {
            pNwfIEngine = _bootstraper("", nWFEngineParamConfig.parentProcessId, nWFEngineParamConfig.parentTaskId, userInfo);
            pNwfEngineParamConfig = pNwfIEngine.getConfig();
            nWFTaskMsgEntity.setToUserid(pNwfEngineParamConfig.createUser.id);
            nWFTaskMsgEntity.setToUsername(pNwfEngineParamConfig.createUser.name);
            nWFTaskMsgEntity.setToUsercode(pNwfEngineParamConfig.createUser.account);
            nWFTaskMsgEntity.setTitle(pNwfEngineParamConfig.schemeName);
            nWFTaskMsgEntity.setContent("你的流程【子流程:" + nWFEngineParamConfig.schemeName + "】有状态的更新：" + nWFEngineParamConfig.currentUser.name + "加签");
            nWFTaskMsgEntity.NodeId = pNwfIEngine.getStartNode().id;
            pTaskMsgList.add(nWFTaskMsgEntity);
        } else {
            taskMsgList.add(nWFTaskMsgEntity);
        }
        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(nWFEngineParamConfig.processId);
        nWFProcessEntity.setIsStart(1);

        save(nWFTaskLogEntity, nWFTaskRelationEntity, taskEntiy, nWFProcessEntity, null, null, taskList, taskMsgList, null);
        _sendMsg(pTaskMsgList, pNwfIEngine);
        _sendMsg(taskMsgList, nWFIEngine);
    }

    @Override
    @Transactional
    public void signAuditFlow(String operationCode, String processId, String taskId, String des, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, taskId, userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        NwfTask taskEntiy = taskService.getEntity(taskId);
        Assert.notNull(taskEntiy, "找不到对应流程任务");
        Assert.isTrue(taskEntiy.getIsFinished() == 0, "该任务已经结束！");
        taskEntiy.setUpdateTime(new Date());
        taskEntiy.setUpdateUserid(userInfo.getId());
        taskEntiy.setUpdateUsername(userInfo.getRealName());
        taskEntiy.setIsFinished(1);
        String taskUserId = userInfo.getId();
        List<NwfTaskRelation> taskUserList = taskService.getTaskUserList(taskId);
        boolean isMyTask = false;
        Map<String, String> taskUserMap = new HashMap<>();
        for (NwfTaskRelation item2 : taskUserList) {
            if (item2.getUserid().equals(userInfo.getId())) {
                isMyTask = true;
            }
            if (!taskUserMap.containsKey(userInfo.getId())) {
                taskUserMap.put(userInfo.getId(), "1");
            }
        }
        if (!isMyTask) {
            for (SysUser item : getDelegateProcess(userInfo.getId())) {
                if (taskUserMap.containsKey(item.getId())) {
                    taskUserId = item.getId();
                }
            }
        }
        SysUser userEntity = userService.findById(taskEntiy.getFirstUserid());
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode(operationCode);
        nWFTaskLogEntity.setOperationName("【加签】" + ((operationCode.equals("agree")) ? "同意" : "不同意"));
        nWFTaskLogEntity.setNodeId(taskEntiy.getNodeId());
        nWFTaskLogEntity.setNodeName(taskEntiy.getNodeName());
        nWFTaskLogEntity.setPrevNodeId(taskEntiy.getPrevNodeId());
        nWFTaskLogEntity.setPrevNodeName(taskEntiy.getPrevNodeName());
        nWFTaskLogEntity.setDescription(des);
        nWFTaskLogEntity.setTaskId(taskId);
        nWFTaskLogEntity.setTaskType(3);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskLogEntity.setTaskUserid(userInfo.getId());
        nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());

        if (!userInfo.getId().equals(taskUserId)) {
            nWFTaskLogEntity.setTaskUserid(taskUserId);
            nWFTaskLogEntity.setTaskUsername(userService.findById(taskUserId).getRealName());
        }
        nWFTaskLogEntity = nWFTaskLogEntity.create();
        NwfTaskMsg nWFTaskMsgEntity = new NwfTaskMsg();
        nWFTaskMsgEntity.setProcessId(nWFEngineParamConfig.processId);
        nWFTaskMsgEntity.setFromUserid(nWFEngineParamConfig.currentUser.id);
        nWFTaskMsgEntity.setFromUsercode(nWFEngineParamConfig.currentUser.account);
        nWFTaskMsgEntity.setFromUsername(nWFEngineParamConfig.currentUser.name);
        nWFTaskMsgEntity.setToUserid(nWFEngineParamConfig.createUser.id);
        nWFTaskMsgEntity.setToUsercode(nWFEngineParamConfig.createUser.account);
        nWFTaskMsgEntity.setToUsername(nWFEngineParamConfig.createUser.name);
        nWFTaskMsgEntity.setTitle(nWFEngineParamConfig.schemeName);
        nWFTaskMsgEntity.setContent("你的流程有状态的更新：" + nWFEngineParamConfig.currentUser.name + "【加签】" + ((operationCode.equals("agree")) ? "同意" : "不同意"));
        nWFTaskMsgEntity.setNodeId(nWFIEngine.getStartNode().id);
        nWFTaskMsgEntity = nWFTaskMsgEntity.create();

        String finalTaskUserId = taskUserId;
        NwfTaskRelation nWFTaskRelationEntity = taskUserList.stream().filter(t -> t.getUserid().equals(finalTaskUserId)).findFirst().get();
        nWFTaskRelationEntity.setCreateTime(new Date());
        if (operationCode.equals("agree")) {
            nWFTaskRelationEntity.setResult(1);
        } else {
            nWFTaskRelationEntity.setResult(2);
        }
        List<NwfTask> taskList = new ArrayList<>();
        nWFIEngine.getNode(taskEntiy.getNodeId());
        NwfTask nWFTaskEntity = new NwfTask();
        nWFTaskEntity = nWFTaskEntity.create();
        nWFTaskEntity.setProcessId(nWFEngineParamConfig.processId);
        nWFTaskEntity.setNodeId(taskEntiy.getNodeId());
        nWFTaskEntity.setNodeName(taskEntiy.getNodeName());
        nWFTaskEntity.setPrevNodeId(taskEntiy.getNodeId());
        nWFTaskEntity.setPrevNodeName(taskEntiy.getNodeName());
        nWFTaskEntity.setCreateUserid(userInfo.getId());
        nWFTaskEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskEntity.setTimeoutAction(taskEntiy.getTimeoutAction());
        nWFTaskEntity.setTimeoutInterval(taskEntiy.getTimeoutInterval());
        nWFTaskEntity.setTimeoutNotice(taskEntiy.getTimeoutNotice());
        nWFTaskEntity.setTimeoutStrategy(taskEntiy.getTimeoutStrategy());
        nWFTaskEntity.userInfoList = new ArrayList<>();

        NwfUserInfo user = new NwfUserInfo();
        user.setId(taskEntiy.getFirstUserid());
        user.setAccount(userEntity.getUserCode());
        user.setName(userEntity.getUserName());
        nWFTaskEntity.userInfoList.add(user);
        ;
        nWFTaskEntity.setTaskType(1);
        taskList.add(nWFTaskEntity);

        List<NwfTaskMsg> taskMsgList = _createTaskMsg(taskList, nWFEngineParamConfig);
        List<NwfTaskMsg> pTaskMsgList = new ArrayList<>();
        NwfEngineParamConfig pNwfEngineParamConfig = null;
        NwfIEngine pNwfIEngine = null;
        if (nWFEngineParamConfig.getIsChild() == 1) {
            pNwfIEngine = _bootstraper("", nWFEngineParamConfig.parentProcessId, nWFEngineParamConfig.parentTaskId, userInfo);
            pNwfEngineParamConfig = pNwfIEngine.getConfig();
            nWFTaskMsgEntity.setToUserid(pNwfEngineParamConfig.createUser.id);
            nWFTaskMsgEntity.setToUsername(pNwfEngineParamConfig.createUser.name);
            nWFTaskMsgEntity.setToUsercode(pNwfEngineParamConfig.createUser.account);
            nWFTaskMsgEntity.setTitle(pNwfEngineParamConfig.schemeName);
            nWFTaskMsgEntity.setContent("你的流程【子流程:" + nWFEngineParamConfig.schemeName + "】有状态的更新：" + nWFEngineParamConfig.currentUser.name + "加签" + ((operationCode.equals("agree")) ? "同意" : "不同意"));
            nWFTaskMsgEntity.NodeId = pNwfIEngine.getStartNode().id;
            pTaskMsgList.add(nWFTaskMsgEntity);
        } else {
            taskMsgList.add(nWFTaskMsgEntity);
        }
        save(nWFTaskLogEntity, nWFTaskRelationEntity, taskEntiy, null, null, null, taskList, taskMsgList, null);
        _sendMsg(pTaskMsgList, pNwfIEngine);
        _sendMsg(taskMsgList, nWFIEngine);
    }

    @Override
    @Transactional
    public void referFlow(String processId, String taskId, SysUser userInfo) {
        NwfTask taskEntiy = taskService.getEntity(taskId);
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("agreeRefer");
        nWFTaskLogEntity.setOperationName("查阅流程");
        nWFTaskLogEntity.setNodeId(taskEntiy.getNodeId());
        nWFTaskLogEntity.setNodeName(taskEntiy.getNodeName());
        nWFTaskLogEntity.setPrevNodeId(taskEntiy.getPrevNodeId());
        nWFTaskLogEntity.setPrevNodeName(taskEntiy.getPrevNodeName());
        nWFTaskLogEntity.setTaskId(taskId);
        nWFTaskLogEntity.setTaskType(2);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskLogEntity.setTaskUserid(userInfo.getId());
        nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());

        nWFTaskLogEntity = nWFTaskLogEntity.create();
        List<NwfTaskRelation> obj = taskService.getTaskUserList(taskId);
        NwfTaskRelation nWFTaskRelationEntity = obj.stream().filter(t -> t.getUserid().equals(userInfo.getId())).findFirst().get();
        nWFTaskRelationEntity.setCreateTime(new Date());
        nWFTaskRelationEntity.setResult(1);

        if (obj.stream().filter(t -> t.getResult() == 0).count() == 0) {
            taskEntiy.setUpdateTime(new Date());
            taskEntiy.setUpdateUserid(userInfo.getId());
            taskEntiy.setUpdateUsername(userInfo.getRealName());
            taskEntiy.setIsFinished(1);
        } else {
            taskEntiy = null;
        }
        save(nWFTaskLogEntity, nWFTaskRelationEntity, taskEntiy);
    }

    @Override
    @Transactional
    public void urgeFlow(String processId, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, "", userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        List<NwfTask> unFinishTaskList = taskService.getUnFinishTaskList(processId);
        List<NwfTask> updateTaskList = new ArrayList<>();
        List<NwfTaskMsg> taskMsgList = new ArrayList<>();
        for (NwfTask item2 : unFinishTaskList) {
            if (item2.getTaskType() == 2 || item2.getTaskType() == 5) {
                continue;
            }
            item2.setIsUrge(1);
            updateTaskList.add(item2);
            List<NwfTaskRelation> obj = taskService.getTaskUserList(item2.getId());
            NwfNodeInfo nodeInfo2 = nWFIEngine.getNode(item2.getNodeId());
            for (NwfTaskRelation user2 : obj) {
                if (user2.getResult() == 0 && user2.getMark() == 0 && !user2.getUserid().equals(userInfo.getId())) {
                    SysUser userEntity2 = userService.findById(user2.getUserid());
                    NwfTaskMsg nWFTaskMsgEntity3 = new NwfTaskMsg();
                    nWFTaskMsgEntity3.setProcessId(processId);
                    nWFTaskMsgEntity3.setFromUserid(userInfo.getId());
                    nWFTaskMsgEntity3.setFromUsercode(userInfo.getUserCode());
                    nWFTaskMsgEntity3.setFromUsername(userInfo.getRealName());
                    nWFTaskMsgEntity3.setToUserid(userEntity2.getId());
                    nWFTaskMsgEntity3.setToUsercode(userEntity2.getUserCode());
                    nWFTaskMsgEntity3.setToUsername(userEntity2.getRealName());
                    nWFTaskMsgEntity3.setTitle(nWFEngineParamConfig.schemeName);
                    nWFTaskMsgEntity3.setContent(nWFEngineParamConfig.schemeName + "：【" + nodeInfo2.name + "】请尽快审核,来自【" + userInfo.getRealName() + "】");
                    nWFTaskMsgEntity3.setNodeId(item2.getNodeId());
                    NwfTaskMsg nWFTaskMsgEntity2 = nWFTaskMsgEntity3;
                    nWFTaskMsgEntity2 = nWFTaskMsgEntity2.create();
                    taskMsgList.add(nWFTaskMsgEntity2);
                    _sendMsg(taskMsgList, nWFIEngine);
                }
            }
        }
        NwfNodeInfo startNodeInfo = nWFIEngine.getStartNode();
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("urgeFlow");
        nWFTaskLogEntity.setOperationName("催办审核");
        nWFTaskLogEntity.setNodeId(startNodeInfo.id);
        nWFTaskLogEntity.setNodeName(startNodeInfo.name);
        nWFTaskLogEntity.setPrevNodeId(startNodeInfo.id);
        nWFTaskLogEntity.setPrevNodeName(startNodeInfo.getName());
        nWFTaskLogEntity.setTaskType(9);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
        nWFTaskLogEntity.setTaskUserid(userInfo.getId());
        nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());

        nWFTaskLogEntity = nWFTaskLogEntity.create();


        Map<String, Object> param = new HashMap<>();
        param.put("parentProcessId", processId);
        List<NwfProcess> childProcessList = processDao.findAll(param);
        for (NwfProcess processEntity : childProcessList) {
            List<NwfTaskMsg> pTaskMsgList = new ArrayList<>();
            List<NwfTask> unFinishTaskList2 = taskService.getUnFinishTaskList(processEntity.getId());
            NwfIEngine pNwfIEngine = _bootstraper("", processEntity.getId(), "", userInfo);
            NwfEngineParamConfig pNwfEngineParamConfig = pNwfIEngine.getConfig();
            for (NwfTask item : unFinishTaskList2) {
                if (item.getTaskType() == 2 || item.getTaskType() == 5) {
                    continue;
                }
                item.setIsUrge(1);
                updateTaskList.add(item);
                List<NwfTaskRelation> obj2 = taskService.getTaskUserList(item.getId());
                NwfNodeInfo nodeInfo = pNwfIEngine.getNode(item.getNodeId());
                for (NwfTaskRelation user : obj2) {
                    if (user.getResult() == 0 && user.getMark() == 0 && !user.getUserid().equals(userInfo.getId())) {
                        SysUser userEntity = userService.findById(user.getUserid());
                        NwfTaskMsg nWFTaskMsgEntity3 = new NwfTaskMsg();
                        nWFTaskMsgEntity3.setProcessId(processEntity.getId());
                        nWFTaskMsgEntity3.setFromUserid(userInfo.getId());
                        nWFTaskMsgEntity3.setFromUsercode(userInfo.getUserName());
                        nWFTaskMsgEntity3.setFromUsername(userInfo.getRealName());
                        nWFTaskMsgEntity3.setToUserid(userEntity.getId());
                        nWFTaskMsgEntity3.setToUsercode(userEntity.getUserName());
                        nWFTaskMsgEntity3.setToUsername(userEntity.getRealName());
                        nWFTaskMsgEntity3.setTitle(nWFEngineParamConfig.schemeName + "的子流程-" + pNwfEngineParamConfig.schemeName);
                        nWFTaskMsgEntity3.setContent(pNwfEngineParamConfig.schemeName + "：【" + nodeInfo.name + "】请尽快审核,来自【" + userInfo.getRealName() + "】");
                        nWFTaskMsgEntity3.NodeId = item.getNodeId();
                        NwfTaskMsg nWFTaskMsgEntity = nWFTaskMsgEntity3;
                        nWFTaskMsgEntity = nWFTaskMsgEntity.create();
                        pTaskMsgList.add(nWFTaskMsgEntity);
                        _sendMsg(pTaskMsgList, pNwfIEngine);
                        taskMsgList.addAll(pTaskMsgList);
                    }
                }
            }
        }
        save(nWFTaskLogEntity, updateTaskList, taskMsgList);
    }

    @Override
    @Transactional
    public void revokeFlow(String processId, SysUser userInfo) {
        if (findById(processId).getIsStart() != 1) {
            NwfIEngine nWFIEngine = _bootstraper("", processId, "", userInfo);
            NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
            com.open.capacity.workflow3.engine.NwfScheme scheme = nWFIEngine.getSchemeObj();
            List<NwfTask> taskList = taskService.getALLTaskList(processId);
            save(processId, taskList, 2, null);
            _triggerMethod(scheme.closeDo, "1", nWFEngineParamConfig);
        }
    }

    @Override
    @Transactional
    public Boolean revokeAudit(String processId, String taskId, SysUser userInfo) {
        boolean res = false;
        NwfIEngine nWFIEngine = _bootstraper("", processId, taskId, userInfo);
        NwfTask taskEntity = taskService.getEntity(taskId);
        NwfNodeInfo nodeEntity = nWFIEngine.getNode(taskEntity.getNodeId());
        NwfTaskLog taskLogEntity = taskService.getLogEntity(taskId, userInfo.getId());
        if (StringUtils.isEmpty(processId)) {
            processId = taskEntity.getProcessId();
        }
        if (!taskService.isRevokeTask(processId, taskEntity.getNodeId())) {
            return false;
        }
        if (taskLogEntity.getTaskType() == 1) {
            if (taskEntity.getIsFinished() == 0 && nodeEntity.isAllAuditor.equals("2")) {
                List<NwfTaskRelation> taskUserList3 = taskService.getTaskUserList(taskEntity.getId());
                NwfTaskRelation taskUserEntity2 = taskUserList3.stream().filter(t -> t.getUserid().equals(userInfo.getId())).findFirst().get();
                if (nodeEntity.auditorType.equals("1")) {
                    NwfTaskLog nWFTaskLogEntity2 = new NwfTaskLog();
                    nWFTaskLogEntity2.setProcessId(processId);
                    nWFTaskLogEntity2.setOperationCode("revokeAudit");
                    nWFTaskLogEntity2.setOperationName("撤销审核");
                    nWFTaskLogEntity2.setNodeId(taskEntity.getNodeId());
                    nWFTaskLogEntity2.setNodeName(taskEntity.getNodeName());
                    nWFTaskLogEntity2.setPrevNodeId(taskEntity.getPrevNodeId());
                    nWFTaskLogEntity2.setPrevNodeName(taskEntity.getPrevNodeName());
                    nWFTaskLogEntity2.setTaskId(taskId);
                    nWFTaskLogEntity2.setTaskType(100);
                    nWFTaskLogEntity2.setCreateUserid(userInfo.getId());
                    nWFTaskLogEntity2.setCreateUsername(userInfo.getRealName());
                    nWFTaskLogEntity2.setTaskUserid(userInfo.getId());
                    nWFTaskLogEntity2.setTaskUsername(userInfo.getRealName());

                    nWFTaskLogEntity2 = nWFTaskLogEntity2.create();
                    _revokeAudit(null, taskUserEntity2, null, nWFTaskLogEntity2, null);
                    return true;
                }
                int sort = taskUserEntity2.getSort() + 1;
                NwfTaskRelation taskUserEntity3 = taskUserList3.stream().filter(t -> t.getSort().equals(sort)).findFirst().get();
                if (taskUserEntity3 != null && taskUserEntity3.getResult() == 0) {
                    NwfTaskLog nWFTaskLogEntity3 = new NwfTaskLog();
                    nWFTaskLogEntity3.setProcessId(processId);
                    nWFTaskLogEntity3.setOperationCode("revokeAudit");
                    nWFTaskLogEntity3.setOperationName("撤销审核");
                    nWFTaskLogEntity3.setNodeId(taskEntity.getNodeId());
                    nWFTaskLogEntity3.setNodeName(taskEntity.getNodeName());
                    nWFTaskLogEntity3.setPrevNodeId(taskEntity.getPrevNodeId());
                    nWFTaskLogEntity3.setPrevNodeName(taskEntity.getPrevNodeName());
                    nWFTaskLogEntity3.setTaskId(taskId);
                    nWFTaskLogEntity3.setTaskType(100);
                    nWFTaskLogEntity3.setCreateUserid(userInfo.getId());
                    nWFTaskLogEntity3.setCreateUsername(userInfo.getRealName());
                    nWFTaskLogEntity3.setTaskUserid(userInfo.getId());
                    nWFTaskLogEntity3.setTaskUsername(userInfo.getRealName());

                    nWFTaskLogEntity3 = nWFTaskLogEntity3.create();
                    _revokeAudit(null, taskUserEntity2, null, nWFTaskLogEntity3, taskUserEntity3);
                    return true;
                }
            } else {
                List<NwfTask> unFinishTaskList = taskService.getUnFinishTaskList(processId);
                List<String> deleteTaskList = new ArrayList<>();
                List<NwfLineInfo> lines = new ArrayList<>();
                for (NwfTask taskItem : unFinishTaskList) {
                    if (taskItem.getPrevNodeId().equals(taskEntity.getNodeId()) && taskItem.getIsFinished() == 0 && taskService.getTaskUserList(taskItem.getId()).stream().filter(t -> t.getResult() != 0).count() == 0) {
                        deleteTaskList.add(taskItem.getId());
                    }
                }
                if (deleteTaskList.size() > 0) {
                    taskEntity.setIsFinished(0);
                    NwfTaskRelation taskUserEntity = (taskService.getTaskUserList(taskEntity.getId())).stream().filter(t -> t.getUserid().equals(userInfo.getId())).findFirst().get();
                    NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
                    nWFTaskLogEntity.setProcessId(processId);
                    nWFTaskLogEntity.setOperationCode("revokeAudit");
                    nWFTaskLogEntity.setOperationName("撤销审核");
                    nWFTaskLogEntity.setNodeId(taskEntity.getNodeId());
                    nWFTaskLogEntity.setNodeName(taskEntity.getNodeName());
                    nWFTaskLogEntity.setPrevNodeId(taskEntity.getPrevNodeId());
                    nWFTaskLogEntity.setPrevNodeName(taskEntity.getPrevNodeName());
                    nWFTaskLogEntity.setTaskId(taskId);
                    nWFTaskLogEntity.setTaskType(100);
                    nWFTaskLogEntity.setCreateUserid(userInfo.getId());
                    nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());
                    nWFTaskLogEntity.setTaskUserid(userInfo.getId());
                    nWFTaskLogEntity.setTaskUsername(userInfo.getRealName());

                    nWFTaskLogEntity = nWFTaskLogEntity.create();
                    _revokeAudit(deleteTaskList, taskUserEntity, taskEntity, nWFTaskLogEntity, null);
                    nWFIEngine.getNextTaskNode(nodeEntity, taskLogEntity.getOperationCode(), false, lines);
                    for (NwfLineInfo line : lines) {
                        _triggerMethodR(line, taskEntity.getId(), taskEntity.getNodeName(), nWFIEngine.getConfig());
                    }
                    return true;
                }
            }
        }
        return res;
    }

    public void makeTaskTimeout() {
        try {
            List<NwfTask> taskList = taskService.getUnFinishTaskList();
            for (NwfTask task : taskList) {
                try {
                    if (task.getCreateTime() == null) {
                        continue;
                    }
                    Date time = task.getCreateTime();
                    boolean isNext = false;
                    if (task.getTimeoutAction() > 0) {
                        Date actionTime = DateUtils.addHours(time, task.getTimeoutAction());
                        if (actionTime.compareTo(new Date()) < 0) {
                            NwfIEngine nWFIEngine = _bootstraper("", task.getProcessId(), task.getId(), null);
                            NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
                            nWFEngineParamConfig.currentUser = new NwfUserInfo();
                            nWFEngineParamConfig.currentUser.id = "System";
                            nWFEngineParamConfig.currentUser.name = "系统";
                            NwfNodeInfo nodeInfo = nWFIEngine.getNode(task.getNodeId());
                            task.setUpdateTime(new Date());
                            task.setIsFinished(2);
                            NwfTaskLog nWFTaskLogEntity2 = new NwfTaskLog();
                            nWFTaskLogEntity2.setProcessId(task.getProcessId());
                            nWFTaskLogEntity2.setOperationCode("lrtimeout");
                            nWFTaskLogEntity2.setOperationName("超时");
                            nWFTaskLogEntity2.setNodeId(task.getNodeId());
                            nWFTaskLogEntity2.setNodeName(task.getNodeName());
                            nWFTaskLogEntity2.setPrevNodeId(task.getPrevNodeId());
                            nWFTaskLogEntity2.setPrevNodeName(task.getPrevNodeName());
                            nWFTaskLogEntity2.setTaskId(task.getId());
                            nWFTaskLogEntity2.setTaskType(6);
                            nWFTaskLogEntity2.setCreateUserid("System");
                            nWFTaskLogEntity2.setCreateUsername("系统");

                            nWFTaskLogEntity2 = nWFTaskLogEntity2.create();
                            NwfTaskMsg nWFTaskMsgEntity2 = new NwfTaskMsg();
                            nWFTaskMsgEntity2.setProcessId(nWFEngineParamConfig.processId);
                            nWFTaskMsgEntity2.setToUserid(nWFEngineParamConfig.createUser.id);
                            nWFTaskMsgEntity2.setToUsercode(nWFEngineParamConfig.createUser.account);
                            nWFTaskMsgEntity2.setToUsername(nWFEngineParamConfig.createUser.name);
                            nWFTaskMsgEntity2.setTitle(nWFEngineParamConfig.schemeName);
                            nWFTaskMsgEntity2.setContent("你的流程有状态的更新：【" + task.getNodeName() + "】超时流转");
                            nWFTaskMsgEntity2.setNodeId(nWFIEngine.getStartNode().id);

                            nWFTaskMsgEntity2 = nWFTaskMsgEntity2.create();
                            List<NwfLineInfo> lineList = new ArrayList<>();
                            List<NwfNodeInfo> list = nWFIEngine.getNextTaskNode(nodeInfo, "lrtimeout", false, lineList);
                            List<NwfTask> nTaskList = _createTask(list, nodeInfo, nWFEngineParamConfig);
                            List<NwfTaskMsg> taskMsgList2 = _createTaskMsg(nTaskList, nWFEngineParamConfig);
                            NwfProcess nWFProcessEntity2 = new NwfProcess();
                            nWFProcessEntity2.setId(nWFEngineParamConfig.processId);
                            nWFProcessEntity2.setIsStart(1);

                            if (nWFEngineParamConfig.state == 1) {
                                nWFProcessEntity2.setIsAgain(1);
                            } else if (nWFEngineParamConfig.state == 2) {
                                nWFProcessEntity2.setIsFinished(1);
                            }
                            List<NwfLineInfo> pLineList = new ArrayList<>();
                            List<NwfTask> pTaskList = new ArrayList<>();
                            List<NwfTaskMsg> pTaskMsgList = new ArrayList<>();
                            NwfEngineParamConfig pNwfEngineParamConfig = null;
                            NwfNodeInfo pNodeInfo = null;
                            NwfIEngine pNwfIEngine = null;
                            NwfProcess pNwfProcess = null;
                            if (nWFEngineParamConfig.getIsChild() == 1) {
                                pNwfIEngine = _bootstraper("", nWFEngineParamConfig.parentProcessId, nWFEngineParamConfig.parentTaskId, null);
                                pNwfEngineParamConfig = pNwfIEngine.getConfig();
                                pNwfEngineParamConfig.currentUser = new NwfUserInfo();
                                nWFTaskMsgEntity2.setToUserid(pNwfEngineParamConfig.createUser.id);
                                nWFTaskMsgEntity2.setToUsername(pNwfEngineParamConfig.createUser.name);
                                nWFTaskMsgEntity2.setToUsercode(pNwfEngineParamConfig.createUser.account);
                                nWFTaskMsgEntity2.setTitle(pNwfEngineParamConfig.schemeName);
                                nWFTaskMsgEntity2.setContent("你的流程【子流程:" + nWFEngineParamConfig.schemeName + "】有状态的更新：【" + task.getNodeName() + "】超时流转");
                                nWFTaskMsgEntity2.NodeId = pNwfIEngine.getStartNode().id;
                                if (findById(nWFEngineParamConfig.processId).getIsAsyn() == 0 && nWFEngineParamConfig.state == 2) {
                                    NwfTask pTaskEntity = taskService.getEntity(nWFEngineParamConfig.parentTaskId);
                                    pNodeInfo = pNwfIEngine.getNode(pTaskEntity.getNodeId());
                                    List<NwfNodeInfo> pList = pNwfIEngine.getNextTaskNode(pNodeInfo, "agree", false, pLineList);
                                    pTaskList = _createTask(pList, pNodeInfo, pNwfEngineParamConfig);
                                    pTaskMsgList = _createTaskMsg(pTaskList, pNwfEngineParamConfig);
                                    if (pNwfEngineParamConfig.state == 1) {
                                        pNwfProcess = new NwfProcess();
                                        pNwfProcess.setIsAgain(1);
                                    } else if (pNwfEngineParamConfig.state == 2) {
                                        pNwfProcess = new NwfProcess();
                                        pNwfProcess.setIsFinished(1);
                                    }
                                }
                                pTaskMsgList.add(nWFTaskMsgEntity2);
                            } else {
                                taskMsgList2.add(nWFTaskMsgEntity2);
                            }
                            _sendMsg(pTaskMsgList, pNwfIEngine);
                            _sendMsg(taskMsgList2, nWFIEngine);
                            nTaskList.addAll(pTaskList);
                            taskMsgList2.addAll(pTaskMsgList);
                            save(nWFTaskLogEntity2, null, task, nWFProcessEntity2, null, null, nTaskList, taskMsgList2, pNwfProcess);
                            for (NwfLineInfo line2 : pLineList) {
                                _triggerMethod(line2, "", pNodeInfo.name, "create", pNwfEngineParamConfig);
                            }
                            for (NwfLineInfo line : lineList) {
                                _triggerMethod(line, task.getId(), nodeInfo.name, "lrtimeout", nWFEngineParamConfig);
                            }
                            for (NwfTask taskItem : taskList) {
                                if (taskItem.getTaskType() == 4) {
                                    NwfNodeInfo cNodeInfo = nWFIEngine.getNode(taskItem.getNodeId());
                                    if (cNodeInfo == null) {
                                        cNodeInfo = pNwfIEngine.getNode(taskItem.getNodeId());
                                        _triggerMethod(cNodeInfo, taskItem.getId(), cNodeInfo.name, taskItem.getChildProcessId(), pNwfEngineParamConfig);
                                    } else {
                                        _triggerMethod(cNodeInfo, taskItem.getId(), cNodeInfo.name, taskItem.getChildProcessId(), nWFEngineParamConfig);
                                    }
                                }
                            }
                            isNext = true;
                        }
                    }
                    if (isNext || StringUtils.isNotEmpty(task.getTimeoutStrategy()) || !(task.getTimeoutNotice() > 0) || !(DateUtils.addHours(time, task.getTimeoutNotice()).compareTo(new Date()) >= 0)) {
                        continue;
                    }
                    NwfProcess nWFProcessEntity = findById(task.getProcessId());
                    List<NwfTaskRelation> obj = taskService.getTaskUserList(task.getId());
                    List<NwfTaskMsg> taskMsgList = new ArrayList<>();
                    List<SysUser> msgUserList = new ArrayList<>();
                    String content = nWFProcessEntity.getSchemeName() + "：【" + task.getNodeName() + "】请尽快审核,来自【系统提醒】";
                    for (NwfTaskRelation taskUser : obj) {
                        SysUser userEntity = userService.findById(taskUser.getUserid());
                        NwfTaskMsg nWFTaskMsgEntity = new NwfTaskMsg();
                        nWFTaskMsgEntity.setProcessId(task.getProcessId());
                        nWFTaskMsgEntity.setToUserid(userEntity.getId());
                        nWFTaskMsgEntity.setToUsercode(userEntity.getUserName());
                        nWFTaskMsgEntity.setToUsername(userEntity.getRealName());
                        nWFTaskMsgEntity.setTitle(nWFProcessEntity.getSchemeName());
                        nWFTaskMsgEntity.setContent(content);

                        nWFTaskMsgEntity = nWFTaskMsgEntity.create();
                        taskMsgList.add(nWFTaskMsgEntity);
                        msgUserList.add(userEntity);
                    }
//                    lR_StrategyInfoIBLL.sendMessage(task.getTimeoutStrategy(), content, msgUserList.ToJson()); //TODO 发送通知
                    NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
                    nWFTaskLogEntity.setProcessId(task.getProcessId());
                    nWFTaskLogEntity.setOperationCode("timeoutFlow");
                    nWFTaskLogEntity.setOperationName("超时提醒");
                    nWFTaskLogEntity.setNodeId(task.getNodeId());
                    nWFTaskLogEntity.setNodeName(task.getNodeName());
                    nWFTaskLogEntity.setPrevNodeId(task.getNodeId());
                    nWFTaskLogEntity.setPrevNodeName(task.getNodeName());
                    nWFTaskLogEntity.setTaskType(10);

                    nWFTaskLogEntity = nWFTaskLogEntity.create();
                    task.setIsUrge(1);
                    if (task.getTimeoutInterval() > 0) {
                        task.setTimeoutNotice(task.getTimeoutNotice() + task.getTimeoutInterval());
                    } else {
                        task.setTimeoutNotice(0);
                    }
                    save(nWFTaskLogEntity, task, taskMsgList);
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {
        }
    }

    public List<NwfTask> getTaskUserList(String processId) {
        if (StringUtils.isEmpty(processId)) {
            return new ArrayList<>();
        }
        List<NwfTask> taskList = taskService.getUnFinishTaskList(processId);
        for (NwfTask item : taskList) {
            item.userInfoList = new ArrayList<>();
            for (NwfTaskRelation user : taskService.getTaskUserList(item.getId())) {
                if (user.getResult() == 0 && user.getMark() == 0) {
                    NwfUserInfo temp = new NwfUserInfo();
                    temp.setId(user.getUserid());
                    item.userInfoList.add(temp);
                }
            }
        }
        return taskList;
    }

    public void appointUser(List<NwfTask> list, SysUser userInfo) {
        List<NwfTaskRelation> nWFTaskRelationlist = new ArrayList<>();
        List<String> taskList = new ArrayList<>();
        String processId = "";
        String content = "";
        for (NwfTask task : list) {
            processId = task.getProcessId();
            taskList.add(task.getId());
            content = content + "【" + task.getNodeName() + "】审核人更新为：";
            for (NwfUserInfo taskUser : task.userInfoList) {
                content = content + taskUser.name + ",";
                NwfTaskRelation relation = new NwfTaskRelation();
                relation.setId(UUIDUtils.getOriginalUUIDWithoutBar());
                relation.setMark(0);
                relation.setTaskId(task.getId());
                relation.setResult(0);
                relation.setUserid(taskUser.getId());
                relation.setCreateTime(new Date());

                nWFTaskRelationlist.add(relation);

            }
            content = content.substring(0, content.length() - 1);
            content += ";";
        }
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("appoint");
        nWFTaskLogEntity.setOperationName(content);
        nWFTaskLogEntity.setTaskType(100);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());

        nWFTaskLogEntity = nWFTaskLogEntity.create();
        taskService.save(nWFTaskRelationlist, taskList, nWFTaskLogEntity);
    }

    public void deleteFlow(String processId, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, "", userInfo);
        NwfEngineParamConfig nWFEngineParamConfig = nWFIEngine.getConfig();
        com.open.capacity.workflow3.engine.NwfScheme scheme = nWFIEngine.getSchemeObj();
        List<NwfTask> taskList = taskService.getALLTaskList(processId);
        NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
        nWFTaskLogEntity.setProcessId(processId);
        nWFTaskLogEntity.setOperationCode("deleteFlow");
        nWFTaskLogEntity.setOperationName("作废流程");
        nWFTaskLogEntity.setTaskType(100);
        nWFTaskLogEntity.setCreateUserid(userInfo.getId());
        nWFTaskLogEntity.setCreateUsername(userInfo.getRealName());

        nWFTaskLogEntity = nWFTaskLogEntity.create();
        save(processId, taskList, 3, nWFTaskLogEntity);

        Map<String, Object> param = new HashMap<>();
        param.put("parentProcessId", processId);
        List<NwfProcess> childProcessList = processDao.findAll(param);
        for (NwfProcess processEntity : childProcessList) {
            NwfEngineParamConfig cNwfEngineParamConfig = _bootstraper("", processEntity.getId(), "", userInfo).getConfig();
            com.open.capacity.workflow3.engine.NwfScheme cScheme = nWFIEngine.getSchemeObj();
            List<NwfTask> cTaskList = taskService.getALLTaskList(processEntity.getId());
            save(processEntity.getId(), cTaskList, 3, null);
            _triggerMethod(cScheme.closeDo, "2", cNwfEngineParamConfig);
        }
        _triggerMethod(scheme.closeDo, "2", nWFEngineParamConfig);
    }

    public void addTask(String processId, String bNodeId, String eNodeId, SysUser userInfo) {
        NwfIEngine nWFIEngine = _bootstraper("", processId, "", userInfo);
        NwfNodeInfo bNodeInfo = nWFIEngine.getNode(bNodeId);
        NwfNodeInfo eNodeInfo = nWFIEngine.getNode(eNodeId);
        List<NwfNodeInfo> list = new ArrayList<>();
        list.add(eNodeInfo);
        List<NwfTask> taskList = _createTask(list, bNodeInfo, nWFIEngine.getConfig());
        saveTask(taskList);
    }

    public String getMySql() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("SELECT p.create_time,p.id,p.scheme_id,p.scheme_code,p.scheme_name,p.process_title,p.process_level,p.enabled_mark,p.is_again,p.is_finished,p.is_child,p.parent_task_id,p.parent_process_id,p.create_userid,p.create_username,p.is_start" +
                "FROM nwf_process p" +
                "WHERE p.create_userid = #{userId} AND p.is_child = 0 ");
        return stringBuilder.toString();
    }

    @Override
    public String getMyTaskSql(SysUser userInfo, Boolean isBatchAudit) {
        StringBuilder strSql = new StringBuilder();
        strSql.append("SELECT t.id AS task_id,t.task_type,t.node_name AS task_name,t.is_urge,t.update_time,p.F_Id,p.scheme_id,p.scheme_code,p.scheme_name,p.process_title,p.process_level,p.enabled_mark,p.is_again,p.is_finished,p.is_child,p.parent_task_id,p.parent_process_id,p.create_userid,p.create_username,p.is_start" +
                "FROM( SELECT task_id FROM nwf_task_relation r1" +
                "LEFT JOIN nwf_task t1 ON r1.task_id = t1.id " +
                "WHERE r1.mark = 0 AND r1.result = 0 AND (r1.userid  = #{userId} ");
        for (SysUser item : getDelegateProcess(userInfo.getId())) {
            String processId = "'" + item.getWfProcessId().replace(",", "','") + "'";
            String userI2 = "'" + item.getId() + "'";
            strSql.append("  OR (r1.userid =" + userI2 + " AND t1.process_id in (" + processId + ") AND t1.task_type != 2 )");
        }
        strSql.append(") GROUP BY task_id) r" +
                "LEFT JOIN nwf_task t ON t.id = r.task_id" +
                "LEFT JOIN nwf_process p ON p.id = t.process_id" +
                "WHERE t.is_finished = 0  AND (p.is_finished = 0 OR t.task_type = 2)");
        if (isBatchAudit) {
            strSql.append(" AND t.is_batch_audit = 1 ");
        }
        return strSql.toString();
    }

    @Override
    public String getMyFinishTaskSql() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("SELECT t.task_id,t.task_type,t.task_name,t.create_time,p.process_title,p.id,p.scheme_id,p.scheme_code,p.scheme_name,p.process_level,p.enabled_mark,p.is_again,p.is_finished,p.is_child,p.parent_task_id,p.parent_process_id,p.create_userid,p.create_username,p.is_start" +
                " FROM( SELECT MAX(t.id) AS task_id,MAX(t.task_type) AS task_type,MAX(t.node_name) AS task_name,MAX(r.create_time) AS create_time,t.process_id" +
                " FROM nwf_task t LEFT JOIN nwf_task_relation r ON r.task_id = t.id" +
                " WHERE(r.result = 1 OR r.result = 2 OR r.result = 4) AND r.userid = #{userId}" +
                " GROUP BY t.node_id,process_id) t" +
                " LEFT JOIN nwf_process p ON t.process_id = p.id ");
        return stringBuilder.toString();
    }

    public List<SysUser> getDelegateProcess(String userId) {
        List<SysUser> delegateUserlist = new ArrayList<>();
        Date datatime = new Date();
        Map<String, Object> param = new HashMap<>();
        param.put("toUserid", userId);
        param.put("currentDate", DateUtil.format(datatime));
        List<NwfDelegateRule> list = delegateRuleDao.findAll(param);
        for (NwfDelegateRule item : list) {
            SysUser userinfo = new SysUser();
            userinfo.setId(item.getCreateUserid());
            StringBuilder strSql = new StringBuilder();
            strSql.append("SELECT p.id FROM nwf_delegate_relation d" +
                    " LEFT JOIN nwf_schemeinfo s ON s.id = d.scheme_info_id" +
                    " LEFT JOIN nwf_process p ON p.scheme_code = s.code" +
                    " WHERE p.id IS NOT NULL AND p.is_finished = 0 AND d.delegate_rule_id = #{delegateRuleId} ");

            Map<String, Object> p = new HashMap<>();
            p.put("delegateRuleId", item.getId());

            List<Map<String, Object>> dataTable = formDbTableService.findData("core", strSql.toString(), p);
            userinfo.setWfProcessId("");
            for (Map<String, Object> dr : dataTable) {
                if (StringUtils.isNotEmpty(dr.get(0).toString())) {
                    if (StringUtils.isNotEmpty(userinfo.getWfProcessId())) {
                        userinfo.setWfProcessId(userinfo.getWfProcessId() + ",");
                    }
                    userinfo.setWfProcessId(userinfo.getWfProcessId() + dr.get(0).toString());
                }
            }
            if (StringUtils.isNotEmpty(userinfo.getWfProcessId())) {
                delegateUserlist.add(userinfo);
            }
        }
        return delegateUserlist;

    }

    @Transactional
    public void save(NwfTaskLog pTaskLogEntity, NwfTaskRelation pTaskRelationEntity, NwfTask pTaskEntityUpdate, NwfProcess pProcessEntity, List<NwfTask> pTaskList, List<NwfTaskMsg> pTaskMsgList, NwfProcess nWFProcessEntity, List<NwfTask> taskList, List<NwfTaskMsg> taskMsgList, NwfTaskLog taskLogEntity) {
        NwfProcess nWFProcessEntityTmp = findById(nWFProcessEntity.getId());
        Map<String, Object> param = new HashMap<>();
        param.put("processId", nWFProcessEntity.getId());
        param.put("nodeId", taskLogEntity.getNodeId());
        param.put("isFinished", 0);
        List<NwfTask> uTaskList = taskDao.findAll(param);
        if (nWFProcessEntityTmp == null) {
            processDao.save(nWFProcessEntity);
        } else {
            processDao.update(nWFProcessEntity);
        }
        for (NwfTask task2 : taskList) {
            task2.setUpdateTime(new Date());
            taskDao.save(task2);
            int num2 = 1;
            if (CollectionUtils.isEmpty(task2.getUserInfoList())) {
                continue;
            }
            for (NwfUserInfo taskUser2 : task2.getUserInfoList()) {
                NwfTaskRelation nWFTaskRelationEntity2 = new NwfTaskRelation();
                nWFTaskRelationEntity2 = nWFTaskRelationEntity2.create();
                nWFTaskRelationEntity2.setTaskId(task2.getId());
                nWFTaskRelationEntity2.setUserid(taskUser2.getId());
                nWFTaskRelationEntity2.setMark(taskUser2.getMark());
                nWFTaskRelationEntity2.setResult(0);
                nWFTaskRelationEntity2.setMark(0);
                nWFTaskRelationEntity2.setSort(num2);
                taskRelationDao.save(nWFTaskRelationEntity2);
                num2++;
            }
        }
        for (NwfTaskMsg taskMsg2 : taskMsgList) {
            taskMsgDao.save(taskMsg2);
        }
        taskLogDao.save(taskLogEntity);
        for (NwfTask item : uTaskList) {
            item.setIsFinished(1);
            taskDao.update(item);
        }
        taskLogDao.save(pTaskLogEntity);
        taskRelationDao.update(pTaskRelationEntity);
        taskDao.update(pTaskEntityUpdate);
        if (pProcessEntity != null) {
            processDao.update(pProcessEntity);
        }
        for (NwfTask task : pTaskList) {
            task.setUpdateTime(new Date());
            taskDao.save(task);
            int num = 1;
            if (CollectionUtils.isEmpty(task.userInfoList)) {
                continue;
            }
            for (NwfUserInfo taskUser : task.userInfoList) {
                NwfTaskRelation nWFTaskRelationEntity = new NwfTaskRelation();
                nWFTaskRelationEntity = nWFTaskRelationEntity.create();
                nWFTaskRelationEntity.setTaskId(task.getId());
                nWFTaskRelationEntity.setUserid(taskUser.getId());
                nWFTaskRelationEntity.setMark(taskUser.getMark());
                nWFTaskRelationEntity.setResult(0);
                nWFTaskRelationEntity.setMark(0);
                nWFTaskRelationEntity.setSort(num);
                taskRelationDao.save(nWFTaskRelationEntity);
                num++;
            }
        }
        for (NwfTaskMsg taskMsg : pTaskMsgList) {
            taskMsgDao.save(taskMsg);
        }
    }

    @Transactional
    public void save(NwfTaskLog taskLogEntity, NwfTaskRelation taskRelationEntity, NwfTask taskEntityUpdate, NwfProcess processEntity, List<NwfConfluence> confluenceList, List<NwfTask> closeTaskList, List<NwfTask> taskList, List<NwfTaskMsg> taskMsgList, NwfProcess pProcessEntity) {
        if (taskLogEntity.getDescription().equals("无审核人跳过") || taskLogEntity.getDescription().equals("系统自动审核")) {
            taskLogEntity.setCreateTime(DateUtils.addMilliseconds(taskLogEntity.getCreateTime(), 10));
        }
        taskLogDao.save(taskLogEntity);
        if (taskRelationEntity != null) {
            taskRelationDao.update(taskRelationEntity);
        }
        taskDao.update(taskEntityUpdate);
        if (processEntity != null) {
            processDao.update(processEntity);
        }
        if (pProcessEntity != null) {
            processDao.update(pProcessEntity);
        }
        if (confluenceList != null) {
            for (NwfConfluence item2 : confluenceList) {
                if (item2.isClear) {
                    String processId = item2.getProcessId();
                    String nodeId = item2.getNodeId();

                    confluenceDao.deleteByNodeId(processId, nodeId);

                    NwfTaskLog nWFTaskLogEntity = new NwfTaskLog();
                    nWFTaskLogEntity.setProcessId(processId);
                    nWFTaskLogEntity.setOperationCode("confluence");
                    nWFTaskLogEntity.setOperationName("会签" + ((item2.confluenceRes == 1) ? "通过" : "不通过"));
                    nWFTaskLogEntity.setNodeId(item2.getNodeId());
                    nWFTaskLogEntity.setTaskType(7);

                    nWFTaskLogEntity = nWFTaskLogEntity.create();
                    taskLogDao.save(nWFTaskLogEntity);
                } else {
                    confluenceDao.save(item2);
                }
            }
        }
        if (closeTaskList != null) {
            for (NwfTask item : closeTaskList) {
                taskDao.update(item);
            }
        }
        for (NwfTask task : taskList) {
            task.setUpdateTime(new Date());
            taskDao.save(task);
            int num = 1;
            if (CollectionUtils.isEmpty(task.getUserInfoList())) {
                continue;
            }
            for (NwfUserInfo taskUser : task.getUserInfoList()) {
                NwfTaskRelation nWFTaskRelationEntity = new NwfTaskRelation();
                nWFTaskRelationEntity = nWFTaskRelationEntity.create();
                nWFTaskRelationEntity.setTaskId(task.getId());
                nWFTaskRelationEntity.setUserid(taskUser.getId());
                nWFTaskRelationEntity.setMark(taskUser.getMark());
                nWFTaskRelationEntity.setResult(0);
                nWFTaskRelationEntity.setMark(0);
                nWFTaskRelationEntity.setSort(num);
                taskRelationDao.save(nWFTaskRelationEntity);
                num++;
            }
        }
        for (NwfTaskMsg taskMsg : taskMsgList) {
            taskMsgDao.save(taskMsg);
        }
    }

    @Transactional
    public void save(String processId, List<NwfTask> taskList, int EnabledMark, NwfTaskLog nWFTaskLogEntity) {
        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(processId);
        nWFProcessEntity.setEnabledMark(EnabledMark);
        processDao.update(nWFProcessEntity);
        if (EnabledMark == 2) {
            processDao.delete(processId);
        }
        for (NwfTask task : taskList) {
            taskDao.delete(task.getId());
            String taskId = task.getId();
            taskMsgDao.deleteByTaskId(taskId);

            taskRelationDao.deleteByTaskId(taskId);
        }
        if (nWFTaskLogEntity != null) {
            taskLogDao.save(nWFTaskLogEntity);
        }
    }

    @Transactional
    public void save(NwfTaskLog nWFTaskLogEntity, NwfTask task, List<NwfTaskMsg> taskMsgList) {
        taskLogDao.save(nWFTaskLogEntity);
        task.setUpdateTime(new Date());
        taskDao.update(task);
        for (NwfTaskMsg item : taskMsgList) {
            taskMsgDao.save(item);
        }
    }

    @Transactional
    public void save(NwfTaskLog nWFTaskLogEntity, NwfTaskRelation nWFTaskRelationEntity, NwfTask taskEntity) {
        taskLogDao.save(nWFTaskLogEntity);
        taskRelationDao.update(nWFTaskRelationEntity);
        if (taskEntity != null) {
            taskEntity.setUpdateTime(new Date());
            taskDao.update(taskEntity);
        }
    }

    @Transactional
    public void save(NwfTaskLog nWFTaskLogEntity, List<NwfTask> taskList, List<NwfTaskMsg> taskMsgList) {
        taskLogDao.save(nWFTaskLogEntity);
        for (NwfTask item2 : taskList) {
            item2.setUpdateTime(new Date());
            taskDao.update(item2);
        }
        for (NwfTaskMsg item : taskMsgList) {
            taskMsgDao.save(item);
        }
    }

    @Transactional
    public void save(NwfTaskLog nWFTaskLogEntity, List<NwfTaskRelation> taskUserUpdateList, NwfTaskMsg nWFTaskMsgEntity) {
        taskLogDao.save(nWFTaskLogEntity);
        for (NwfTaskRelation item : taskUserUpdateList) {
            taskRelationDao.update(item);
        }
        taskMsgDao.save(nWFTaskMsgEntity);
    }

    @Transactional
    public void save(NwfProcess nWFProcessEntity, List<NwfTask> taskList, List<NwfTaskMsg> taskMsgList, NwfTaskLog taskLogEntity) {
        NwfProcess nWFProcessEntityTmp = processDao.findById(nWFProcessEntity.getId());

        if (nWFProcessEntityTmp == null) {
            processDao.save(nWFProcessEntity);
        } else {
            processDao.update(nWFProcessEntity);
        }
        for (NwfTask task : taskList) {
            task.setUpdateTime(new Date());
            taskDao.save(task);
            int num = 1;
            if (CollectionUtils.isEmpty(task.getUserInfoList())) {
                continue;
            }
            for (NwfUserInfo taskUser : task.getUserInfoList()) {
                NwfTaskRelation nWFTaskRelationEntity = new NwfTaskRelation();
                nWFTaskRelationEntity = nWFTaskRelationEntity.create();
                nWFTaskRelationEntity.setTaskId(task.getId());
                nWFTaskRelationEntity.setUserid(taskUser.getId());
                nWFTaskRelationEntity.setMark(taskUser.getMark());
                nWFTaskRelationEntity.setResult(0);
                nWFTaskRelationEntity.setMark(0);
                nWFTaskRelationEntity.setSort(num);
                taskRelationDao.save(nWFTaskRelationEntity);
                num++;
            }
        }
        for (NwfTaskMsg taskMsg : taskMsgList) {
            taskMsgDao.save(taskMsg);
        }
        taskLogDao.save(taskLogEntity);
    }

    @Transactional
    public void saveTask(List<NwfTask> taskList) {
        for (NwfTask task : taskList) {
            task.setUpdateTime(new Date());
            taskDao.save(task);
            int num = 1;
            if (CollectionUtils.isEmpty(task.userInfoList)) {
                continue;
            }
            for (NwfUserInfo taskUser : task.userInfoList) {
                NwfTaskRelation nWFTaskRelationEntity = new NwfTaskRelation();
                nWFTaskRelationEntity = nWFTaskRelationEntity.create();
                nWFTaskRelationEntity.setTaskId(task.getId());
                nWFTaskRelationEntity.setUserid(taskUser.getId());
                nWFTaskRelationEntity.setMark(taskUser.getMark());
                nWFTaskRelationEntity.setResult(0);
                nWFTaskRelationEntity.setMark(0);
                nWFTaskRelationEntity.setSort(num);
                taskRelationDao.save(nWFTaskRelationEntity);
                num++;
            }
        }
    }

    @Transactional
    public void _revokeAudit(List<String> taskList, NwfTaskRelation taskUser, NwfTask taskEntity, NwfTaskLog taskLogEntity, NwfTaskRelation taskUserNew) {
        if (CollectionUtils.isEmpty(taskList)) {
            for (String taskId : taskList) {
                taskDao.delete(taskId);
                taskRelationDao.deleteByTaskId(taskId);
                taskMsgDao.deleteByTaskId(taskId);
            }
        }
        if (taskEntity != null) {
            taskDao.update(taskEntity);
        }
        taskUser.setMark(0);
        taskUser.setResult(0);
        taskRelationDao.update(taskUser);
        taskLogDao.save(taskLogEntity);
        if (taskUserNew != null) {
            taskUserNew.setMark(1);
            taskUserNew.setResult(0);
            taskRelationDao.update(taskUserNew);
        }
        NwfProcess nWFProcessEntity = new NwfProcess();
        nWFProcessEntity.setId(taskLogEntity.getProcessId());
        nWFProcessEntity.setIsAgain(0);
        processDao.update(nWFProcessEntity);
    }
}

